@fintekkers/ledger-models 0.4.13 → 0.4.15
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/node/wrappers/models/transaction/transaction.d.ts +10 -0
- package/node/wrappers/models/transaction/transaction.js +27 -1
- package/node/wrappers/models/transaction/transaction.js.map +1 -1
- package/node/wrappers/models/transaction/transaction.ts +25 -1
- package/node/wrappers/models/transaction/transaction_price_defaults.test.d.ts +1 -0
- package/node/wrappers/models/transaction/transaction_price_defaults.test.js +131 -0
- package/node/wrappers/models/transaction/transaction_price_defaults.test.js.map +1 -0
- package/node/wrappers/models/transaction/transaction_price_defaults.test.ts +150 -0
- package/node/wrappers/models/utils/requestcontext.auth.test.d.ts +7 -0
- package/node/wrappers/models/utils/requestcontext.auth.test.js +182 -0
- package/node/wrappers/models/utils/requestcontext.auth.test.js.map +1 -0
- package/node/wrappers/models/utils/requestcontext.auth.test.ts +194 -0
- package/node/wrappers/models/utils/requestcontext.d.ts +20 -3
- package/node/wrappers/models/utils/requestcontext.js +44 -13
- package/node/wrappers/models/utils/requestcontext.js.map +1 -1
- package/node/wrappers/models/utils/requestcontext.ts +51 -18
- package/node/wrappers/services/apikey.credentials.test.d.ts +8 -0
- package/node/wrappers/services/apikey.credentials.test.js +101 -0
- package/node/wrappers/services/apikey.credentials.test.js.map +1 -0
- package/node/wrappers/services/apikey.credentials.test.ts +88 -0
- package/package.json +1 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for Issue #114: each wrapper service hands the generated gRPC
|
|
4
|
+
* client the authenticated credentials when given an apiKey, and
|
|
5
|
+
* EnvConfig.apiCredentials otherwise.
|
|
6
|
+
*
|
|
7
|
+
* The generated *_grpc_pb clients are mocked, so no channel is opened.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
jest.mock('../../fintekkers/services/portfolio-service/portfolio_service_grpc_pb', () => ({
|
|
37
|
+
PortfolioClient: jest.fn(),
|
|
38
|
+
}));
|
|
39
|
+
jest.mock('../../fintekkers/services/position-service/position_service_grpc_pb', () => ({
|
|
40
|
+
PositionClient: jest.fn(),
|
|
41
|
+
}));
|
|
42
|
+
jest.mock('../../fintekkers/services/price-service/price_service_grpc_pb', () => ({
|
|
43
|
+
PriceClient: jest.fn(),
|
|
44
|
+
}));
|
|
45
|
+
jest.mock('../../fintekkers/services/security-service/security_service_grpc_pb', () => ({
|
|
46
|
+
SecurityClient: jest.fn(),
|
|
47
|
+
}));
|
|
48
|
+
jest.mock('../../fintekkers/services/transaction-service/transaction_service_grpc_pb', () => ({
|
|
49
|
+
TransactionClient: jest.fn(),
|
|
50
|
+
}));
|
|
51
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
52
|
+
const requestcontext_1 = __importDefault(require("../models/utils/requestcontext"));
|
|
53
|
+
const portfolio_service_grpc_pb_1 = require("../../fintekkers/services/portfolio-service/portfolio_service_grpc_pb");
|
|
54
|
+
const position_service_grpc_pb_1 = require("../../fintekkers/services/position-service/position_service_grpc_pb");
|
|
55
|
+
const price_service_grpc_pb_1 = require("../../fintekkers/services/price-service/price_service_grpc_pb");
|
|
56
|
+
const security_service_grpc_pb_1 = require("../../fintekkers/services/security-service/security_service_grpc_pb");
|
|
57
|
+
const transaction_service_grpc_pb_1 = require("../../fintekkers/services/transaction-service/transaction_service_grpc_pb");
|
|
58
|
+
const PortfolioService_1 = require("./portfolio-service/PortfolioService");
|
|
59
|
+
const PositionService_1 = require("./position-service/PositionService");
|
|
60
|
+
const PriceService_1 = require("./price-service/PriceService");
|
|
61
|
+
const SecurityService_1 = require("./security-service/SecurityService");
|
|
62
|
+
const TransactionService_1 = require("./transaction-service/TransactionService");
|
|
63
|
+
const cases = [
|
|
64
|
+
['PortfolioService', PortfolioService_1.PortfolioService, portfolio_service_grpc_pb_1.PortfolioClient],
|
|
65
|
+
['PositionService', PositionService_1.PositionService, position_service_grpc_pb_1.PositionClient],
|
|
66
|
+
['PriceService', PriceService_1.PriceService, price_service_grpc_pb_1.PriceClient],
|
|
67
|
+
['SecurityService', SecurityService_1.SecurityService, security_service_grpc_pb_1.SecurityClient],
|
|
68
|
+
['TransactionService', TransactionService_1.TransactionService, transaction_service_grpc_pb_1.TransactionClient],
|
|
69
|
+
];
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
jest.clearAllMocks();
|
|
72
|
+
});
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
jest.restoreAllMocks();
|
|
75
|
+
});
|
|
76
|
+
describe.each(cases)('%s', (_name, Service, Client) => {
|
|
77
|
+
const ClientMock = Client;
|
|
78
|
+
test('with apiKey, client gets the authenticated credentials', () => {
|
|
79
|
+
const sentinel = {
|
|
80
|
+
credentials: grpc.credentials.createInsecure(),
|
|
81
|
+
interceptors: [],
|
|
82
|
+
};
|
|
83
|
+
const authSpy = jest
|
|
84
|
+
.spyOn(requestcontext_1.default, 'getAuthenticatedClientOptions')
|
|
85
|
+
.mockReturnValue(sentinel);
|
|
86
|
+
new Service('k');
|
|
87
|
+
expect(authSpy).toHaveBeenCalledWith('k');
|
|
88
|
+
expect(ClientMock).toHaveBeenCalledTimes(1);
|
|
89
|
+
expect(ClientMock).toHaveBeenCalledWith(requestcontext_1.default.apiURL, sentinel.credentials, { interceptors: sentinel.interceptors });
|
|
90
|
+
});
|
|
91
|
+
test('zero-arg constructor constructs with EnvConfig.apiCredentials', () => {
|
|
92
|
+
const plain = grpc.credentials.createInsecure();
|
|
93
|
+
jest.spyOn(requestcontext_1.default, 'apiCredentials', 'get').mockReturnValue(plain);
|
|
94
|
+
const authSpy = jest.spyOn(requestcontext_1.default, 'getAuthenticatedClientOptions');
|
|
95
|
+
expect(new Service()).toBeDefined();
|
|
96
|
+
expect(authSpy).not.toHaveBeenCalled();
|
|
97
|
+
expect(ClientMock).toHaveBeenCalledTimes(1);
|
|
98
|
+
expect(ClientMock).toHaveBeenCalledWith(requestcontext_1.default.apiURL, plain);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=apikey.credentials.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apikey.credentials.test.js","sourceRoot":"","sources":["apikey.credentials.test.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,IAAI,CAAC,IAAI,CAAC,uEAAuE,EAAE,GAAG,EAAE,CAAC,CAAC;IACxF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G,CAAC,gBAAgB,EAAE,CAAC;QACvC,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC,wBAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for Issue #114: each wrapper service hands the generated gRPC
|
|
3
|
+
* client the authenticated credentials when given an apiKey, and
|
|
4
|
+
* EnvConfig.apiCredentials otherwise.
|
|
5
|
+
*
|
|
6
|
+
* The generated *_grpc_pb clients are mocked, so no channel is opened.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
jest.mock('../../fintekkers/services/portfolio-service/portfolio_service_grpc_pb', () => ({
|
|
10
|
+
PortfolioClient: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
jest.mock('../../fintekkers/services/position-service/position_service_grpc_pb', () => ({
|
|
13
|
+
PositionClient: jest.fn(),
|
|
14
|
+
}));
|
|
15
|
+
jest.mock('../../fintekkers/services/price-service/price_service_grpc_pb', () => ({
|
|
16
|
+
PriceClient: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
jest.mock('../../fintekkers/services/security-service/security_service_grpc_pb', () => ({
|
|
19
|
+
SecurityClient: jest.fn(),
|
|
20
|
+
}));
|
|
21
|
+
jest.mock('../../fintekkers/services/transaction-service/transaction_service_grpc_pb', () => ({
|
|
22
|
+
TransactionClient: jest.fn(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
import * as grpc from '@grpc/grpc-js';
|
|
26
|
+
import EnvConfig from '../models/utils/requestcontext';
|
|
27
|
+
import { PortfolioClient } from '../../fintekkers/services/portfolio-service/portfolio_service_grpc_pb';
|
|
28
|
+
import { PositionClient } from '../../fintekkers/services/position-service/position_service_grpc_pb';
|
|
29
|
+
import { PriceClient } from '../../fintekkers/services/price-service/price_service_grpc_pb';
|
|
30
|
+
import { SecurityClient } from '../../fintekkers/services/security-service/security_service_grpc_pb';
|
|
31
|
+
import { TransactionClient } from '../../fintekkers/services/transaction-service/transaction_service_grpc_pb';
|
|
32
|
+
import { PortfolioService } from './portfolio-service/PortfolioService';
|
|
33
|
+
import { PositionService } from './position-service/PositionService';
|
|
34
|
+
import { PriceService } from './price-service/PriceService';
|
|
35
|
+
import { SecurityService } from './security-service/SecurityService';
|
|
36
|
+
import { TransactionService } from './transaction-service/TransactionService';
|
|
37
|
+
|
|
38
|
+
const cases: Array<[string, new (apiKey?: string) => unknown, unknown]> = [
|
|
39
|
+
['PortfolioService', PortfolioService, PortfolioClient],
|
|
40
|
+
['PositionService', PositionService, PositionClient],
|
|
41
|
+
['PriceService', PriceService, PriceClient],
|
|
42
|
+
['SecurityService', SecurityService, SecurityClient],
|
|
43
|
+
['TransactionService', TransactionService, TransactionClient],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
jest.clearAllMocks();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
jest.restoreAllMocks();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe.each(cases)('%s', (_name, Service, Client) => {
|
|
55
|
+
const ClientMock = Client as jest.Mock;
|
|
56
|
+
|
|
57
|
+
test('with apiKey, client gets the authenticated credentials', () => {
|
|
58
|
+
const sentinel = {
|
|
59
|
+
credentials: grpc.credentials.createInsecure(),
|
|
60
|
+
interceptors: [] as grpc.Interceptor[],
|
|
61
|
+
};
|
|
62
|
+
const authSpy = jest
|
|
63
|
+
.spyOn(EnvConfig, 'getAuthenticatedClientOptions')
|
|
64
|
+
.mockReturnValue(sentinel);
|
|
65
|
+
|
|
66
|
+
new Service('k');
|
|
67
|
+
|
|
68
|
+
expect(authSpy).toHaveBeenCalledWith('k');
|
|
69
|
+
expect(ClientMock).toHaveBeenCalledTimes(1);
|
|
70
|
+
expect(ClientMock).toHaveBeenCalledWith(
|
|
71
|
+
EnvConfig.apiURL,
|
|
72
|
+
sentinel.credentials,
|
|
73
|
+
{ interceptors: sentinel.interceptors }
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('zero-arg constructor constructs with EnvConfig.apiCredentials', () => {
|
|
78
|
+
const plain = grpc.credentials.createInsecure();
|
|
79
|
+
jest.spyOn(EnvConfig, 'apiCredentials', 'get').mockReturnValue(plain);
|
|
80
|
+
const authSpy = jest.spyOn(EnvConfig, 'getAuthenticatedClientOptions');
|
|
81
|
+
|
|
82
|
+
expect(new Service()).toBeDefined();
|
|
83
|
+
|
|
84
|
+
expect(authSpy).not.toHaveBeenCalled();
|
|
85
|
+
expect(ClientMock).toHaveBeenCalledTimes(1);
|
|
86
|
+
expect(ClientMock).toHaveBeenCalledWith(EnvConfig.apiURL, plain);
|
|
87
|
+
});
|
|
88
|
+
});
|