UNPKG

component-dbs-core

Version:

DTO objects shared among device backend

216 lines 7.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tableSchema_1 = require("./tableSchema"); describe('transaction db schema test suite', () => { it('should be able to ignore unknown attributes when converting to js object', () => { const item = { unknown: { S: 'this is unknown' }, id: { S: '001' }, amount: { N: '100' }, 'aws:rep:updatetime': { N: '1594608723.881001', }, }; const js = tableSchema_1.unmarshallTransaction(item); expect(js).toMatchObject({ id: '001', amount: 100 }); }); it('should be able to convert wrong type to js object', () => { const item = { id: { S: '001' }, amount: { S: 'wrong value' }, }; const js = tableSchema_1.unmarshallTransaction(item); expect(js).toMatchObject({ id: '001', amount: undefined }); }); it('should be able to convert unknown js attributes to db item', () => { const transaction = { id: '001', unknown: 'unknown', amount: 200, }; const item = tableSchema_1.marshallTransaction(transaction); expect(item).toMatchObject({ id: { S: '001' }, amount: { N: '200' }, }); }); it('should be able to convert wrong js attribute to db item', () => { const transaction = { id: '001', amount: 'wrong', }; const item = tableSchema_1.marshallTransaction(transaction); expect(item).toMatchObject({ id: { S: '001' }, amount: { N: 'wrong' }, }); }); it('should be able to convert nested db item to js object', () => { const item = { id: { S: '001' }, taxAmounts: { L: [ { M: { amount: { N: '100', }, name: { S: 'name', }, }, }, ], }, }; const unmarshed = tableSchema_1.unmarshallTransaction(item); expect(unmarshed).toMatchObject({ id: '001', taxAmounts: [{ name: 'name', amount: 100 }], }); }); it('should be able to convert js nested object to db item', () => { const obj = { id: '001', taxAmounts: [{ name: 'name', amount: 100 }], }; const item = tableSchema_1.marshallTransaction(obj); expect(item).toMatchObject({ id: { S: '001' }, taxAmounts: { L: [ { M: { amount: { N: '100', }, name: { S: 'name', }, }, }, ], }, }); }); it('should be able to convert dynamodb item to javascript object', () => { const item = { surchargeAmount: { N: '500', }, scheme: { S: 'AMEX', }, siteName: { S: 'ac1260b5-9b90-49eb-a5fd-3e94b084bc5d', }, type: { S: 'transaction.1594608546752', }, deviceName: { S: 'b6b0abd4-9e7b-4304-8d49-6f24f9b02cc5', }, reference: { S: 'ab2a1b13-08e8-410b-9270-b2b3b07468ac', }, 'aws:rep:updatetime': { N: '1594608723.881001', }, depositDate: { S: '2020-07-13T02:49:06.752Z', }, panToken: { S: '73c5e6d2-2a7e-4ca9-99bf-4a22526b611b', }, id: { S: '65c3140c-b6d0-4675-9e7e-fbc4750910cd', }, 'aws:rep:updateregion': { S: 'ap-southeast-2', }, siteUuid: { S: '5625a830-7009-40d6-abee-12d29b255ee6', }, timestamp: { S: '2020-07-13T02:49:06.752Z', }, par: { S: '0df5d91f-dec7-4631-8727-f2479bf0c6d3', }, saleAmount: { N: '100', }, amount: { N: '200', }, maskedPan: { S: 'masked', }, entityUuid: { S: '08e6c957-b3d8-4453-87ee-0dcc7d4adb70', }, tipAmount: { N: '100', }, 'aws:rep:deleting': { BOOL: false, }, transactionType: { S: 'REFUND', }, feeAmount: { N: '400', }, transactionUuid: { S: 'c18ee19b-1d61-420e-b68b-d9f98b4f34ad', }, taxAmounts: { L: [ { M: { amount: { N: '100', }, name: { S: 'name', }, }, }, ], }, depositUuid: { S: '28fa3831-468c-4c66-aaac-065e54318109', }, status: { S: 'APPROVED', }, }; const unmarshed = tableSchema_1.unmarshallTransaction(item); expect(unmarshed).toMatchObject({ id: '65c3140c-b6d0-4675-9e7e-fbc4750910cd', type: 'transaction.1594608546752', transactionUuid: 'c18ee19b-1d61-420e-b68b-d9f98b4f34ad', entityUuid: '08e6c957-b3d8-4453-87ee-0dcc7d4adb70', siteUuid: '5625a830-7009-40d6-abee-12d29b255ee6', timestamp: '2020-07-13T02:49:06.752Z', amount: 200, saleAmount: 100, taxAmounts: [{ name: 'name', amount: 100 }], scheme: 'AMEX', transactionType: 'REFUND', status: 'APPROVED', maskedPan: 'masked', reference: 'ab2a1b13-08e8-410b-9270-b2b3b07468ac', deviceName: 'b6b0abd4-9e7b-4304-8d49-6f24f9b02cc5', siteName: 'ac1260b5-9b90-49eb-a5fd-3e94b084bc5d', tipAmount: 100, feeAmount: 400, surchargeAmount: 500, depositUuid: '28fa3831-468c-4c66-aaac-065e54318109', depositDate: '2020-07-13T02:49:06.752Z', panToken: '73c5e6d2-2a7e-4ca9-99bf-4a22526b611b', par: '0df5d91f-dec7-4631-8727-f2479bf0c6d3', }); }); }); //# sourceMappingURL=tableSchema.spec.js.map