UNPKG

component-dbs-core

Version:

DTO objects shared among device backend

146 lines 5.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const transactionUtils_1 = require("./transactionUtils"); describe('transaction util test suite', () => { it('should be able to convert transaction db item to transaction interface', () => { const item = { id: 'id', transactionUuid: 't-uuid', type: 'transaction.12345', scheme: "AMEX" /* AMEX */, 'aws:rep:deleting': '123456', 'aws:rep:updatetime': '123456', 'aws:rep:updateregion': '123456', }; const tran = transactionUtils_1.convertDbItemToTransaction(item); expect(tran).toEqual({ id: 't-uuid', deviceUuid: 'id', scheme: "AMEX" /* AMEX */, }); expect(Object.keys(tran).length).toBe(3); }); it('should be able to create transaction from dynamodb stream record', () => { const streamEvent = { dynamodb: { NewImage: { surchargeAmount: { N: '500', }, 'aws:rep:updatetime': { N: '1594608723.881001', }, scheme: { S: 'VI', }, siteName: { S: '5c13a29d-2a5b-4c83-9de8-adfd24fdf23e', }, type: { S: 'transaction.1594266488389', }, deviceName: { S: 'c185b7ac-28c1-4c4a-b281-8a9e799191281', }, reference: { S: 'b3b233de-69a6-41a1-8741-5e4d5f183c44', }, depositDate: { S: '2020-07-09T03:48:08.389Z', }, panToken: { S: '25841f1a-1a9d-4556-9f55-bdf0097d7635', }, id: { S: '0788f6b3-29ae-4098-b65d-97394fac1549', }, 'aws:rep:updateregion': { S: 'ap-southeast-2', }, siteUuid: { S: '4163b32d-40c4-46f7-b24c-65370a5bd945', }, timestamp: { S: '2020-07-09T03:48:08.389Z', }, par: { S: '5e1ead59-efd5-4e1e-9931-20bd8cc8fc0e', }, saleAmount: { N: '0', }, amount: { N: '200', }, maskedPan: { S: 'masked', }, entityUuid: { S: 'aentityUuid', }, tipAmount: { N: '100', }, 'aws:rep:deleting': { BOOL: false, }, transactionType: { S: 'PURCHASE', }, feeAmount: { N: '400', }, transactionUuid: { S: '4ba93597-660e-46eb-9e68-a272d6a74d3d', }, depositUuid: { S: 'b68a8ca4-4c62-4bee-a557-fa21b763cfd9', }, status: { S: 'APPROVED', }, taxAmounts: { L: [ { M: { amount: { N: '100', }, name: { S: 'name', }, }, }, ], }, }, }, }; const transaction = transactionUtils_1.convertDbStreamToTransaction(streamEvent); expect(transaction).not.toBeUndefined(); expect(transaction).toMatchObject({ amount: 200, depositDate: '2020-07-09T03:48:08.389Z', depositUuid: 'b68a8ca4-4c62-4bee-a557-fa21b763cfd9', deviceName: 'c185b7ac-28c1-4c4a-b281-8a9e799191281', deviceUuid: '0788f6b3-29ae-4098-b65d-97394fac1549', entityUuid: 'aentityUuid', feeAmount: 400, id: '4ba93597-660e-46eb-9e68-a272d6a74d3d', maskedPan: 'masked', reference: 'b3b233de-69a6-41a1-8741-5e4d5f183c44', saleAmount: 0, scheme: 'VI', siteName: '5c13a29d-2a5b-4c83-9de8-adfd24fdf23e', siteUuid: '4163b32d-40c4-46f7-b24c-65370a5bd945', status: 'APPROVED', surchargeAmount: 500, taxAmounts: [{ name: 'name', amount: 100 }], timestamp: '2020-07-09T03:48:08.389Z', }); }); }); //# sourceMappingURL=transactionUtils.spec.js.map