component-dbs-core
Version:
DTO objects shared among device backend
187 lines • 5.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tableSchema_1 = require("./tableSchema");
describe('deposit 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' },
depositAmount: { N: '100' },
'aws:rep:updatetime': {
N: '1594608723.881001',
},
};
const js = tableSchema_1.unmarshallDeposit(item);
expect(js).toMatchObject({ id: '001', depositAmount: 100 });
});
it('should be able to convert wrong type to js object', () => {
const item = {
id: { S: '001' },
depositAmount: { S: 'wrong value' },
};
const js = tableSchema_1.unmarshallDeposit(item);
expect(js).toMatchObject({ id: '001', depositAmount: undefined });
});
it('should be able to convert unknown js attributes to db item', () => {
const transaction = {
id: '001',
unknown: 'unknown',
depositAmount: 200,
};
const item = tableSchema_1.marshallDeposit(transaction);
expect(item).toMatchObject({
id: { S: '001' },
depositAmount: { N: '200' },
});
});
it('should be able to convert wrong js attribute to db item', () => {
const transaction = {
id: '001',
depositAmount: 'wrong',
};
const item = tableSchema_1.marshallDeposit(transaction);
expect(item).toMatchObject({
id: { S: '001' },
depositAmount: { N: 'wrong' },
});
});
it('should be able to convert nested db item to js object', () => {
const item = {
id: { S: '001' },
dailyTotals: {
L: [
{
M: {
amount: {
N: '100',
},
date: {
S: '2020-07-22',
},
},
},
],
},
};
const unmarshed = tableSchema_1.unmarshallDeposit(item);
expect(unmarshed).toMatchObject({
id: '001',
dailyTotals: [{ date: '2020-07-22', amount: 100 }],
});
});
it('should be able to convert js nested object to db item', () => {
const obj = {
id: '001',
dailyTotals: [{ date: '2020-07-22', amount: 100 }],
};
const item = tableSchema_1.marshallDeposit(obj);
expect(item).toMatchObject({
id: { S: '001' },
dailyTotals: {
L: [
{
M: {
amount: {
N: '100',
},
date: {
S: '2020-07-22',
},
},
},
],
},
});
});
it('should be able to convert dynamodb item to javascript object', () => {
const item = {
id: {
S: '65c3140c-b6d0-4675-9e7e-fbc4750910cd',
},
'aws:rep:updateregion': {
S: 'ap-southeast-2',
},
depositUuid: {
S: 'b6b0abd4-9e7b-4304-8d49-6f24f9b02cc5',
},
entityUuid: {
S: 'b6b0abd4-9e7b-4304-8d49-6f24f9b02cc5',
},
timestamp: {
S: '2020-07-13T02:49:06.752Z',
},
status: {
S: 'DEPOSITED',
},
dailyTotals: {
L: [
{
M: {
amount: {
N: '100',
},
date: {
S: '2020-07-13',
},
},
},
],
},
account: {
S: 'account',
},
reference: {
S: 'reference',
},
totalAmount: {
N: '100',
},
type: {
S: 'deposit.1594608546752',
},
feeAmount: {
N: '100',
},
refundsAmount: {
N: '100',
},
chargeBacksAmount: {
N: '100',
},
'aws:rep:deleting': {
BOOL: false,
},
owingAmount: {
N: '100',
},
adjustedAmount: {
N: '100',
},
depositAmount: {
N: '100',
},
};
const unmarshed = tableSchema_1.unmarshallDeposit(item);
expect(unmarshed).toMatchObject({
id: '65c3140c-b6d0-4675-9e7e-fbc4750910cd',
depositUuid: 'b6b0abd4-9e7b-4304-8d49-6f24f9b02cc5',
entityUuid: 'b6b0abd4-9e7b-4304-8d49-6f24f9b02cc5',
timestamp: '2020-07-13T02:49:06.752Z',
status: 'DEPOSITED',
dailyTotals: [{
amount: 100,
date: '2020-07-13',
}],
account: 'account',
reference: 'reference',
totalAmount: 100,
feeAmount: 100,
refundsAmount: 100,
chargeBacksAmount: 100,
owingAmount: 100,
adjustedAmount: 100,
depositAmount: 100,
});
});
});
//# sourceMappingURL=tableSchema.spec.js.map