component-dbs-core
Version:
DTO objects shared among device backend
87 lines • 2.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tableSchema_1 = require("./tableSchema");
describe('device settings 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' },
name: { S: 'device name' },
'aws:rep:updatetime': {
N: '1594608723.881001',
},
};
const js = tableSchema_1.unmarshallDeviceSettings(item);
expect(js).toMatchObject({ id: '001', name: 'device name' });
});
it('should be able to convert nested db item to js object', () => {
const item = {
id: { S: '001' },
site: {
M: {
name: {
S: 'site name',
},
pin: {
S: 'pin code',
},
siteUuid: {
S: 'siteUuid',
},
},
},
receipt: {
M: {
businessName: {
S: 'site name',
},
businessAddress: {
S: 'pin code',
},
footer: {
S: 'siteUuid',
},
logo: {
S: 'siteUuid',
},
enabled: {
BOOL: true,
},
},
},
};
const unmarshed = tableSchema_1.unmarshallDeviceSettings(item);
expect(unmarshed).toMatchObject({
id: '001',
site: { siteUuid: 'siteUuid', name: 'site name', pin: 'pin code' },
receipt: {
enabled: true,
businessName: 'site name',
businessAddress: 'pin code',
footer: 'siteUuid',
logo: 'siteUuid',
},
});
});
it('should be able to convert js nested object to db item', () => {
const obj = {
id: '001',
site: { name: 'site name', pin: '1203' },
};
const item = tableSchema_1.marshallDeviceSettings(obj);
expect(item).toMatchObject({
id: { S: '001' },
site: {
M: {
name: {
S: 'site name',
},
pin: {
S: '1203',
},
},
},
});
});
});
//# sourceMappingURL=tableSchema.spec.js.map