@studyportals/sp-r2d2
Version:
A framework that contains various components used when developing projects that will be deployed via AWS λ.
217 lines • 9.72 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const mocha_1 = require("@testdeck/mocha");
const Moq = require("typemoq");
const attribute_map_normalizer_class_1 = require("../../infrastructure/aws-services-adapters/attribute-map-normalizer.class");
let AttributeMapNormalizerTest = class AttributeMapNormalizerTest {
get testInstance() {
return this.testInstanceMock.object;
}
before() {
this.testInstanceMock = Moq.Mock.ofType(attribute_map_normalizer_class_1.AttributeMapNormalizer);
this.testInstanceMock.callBase = true;
}
normalizeMaps__NormalizedMaps() {
const input = ['SomeInputOne', 'SomeInputTwo'];
const expectedResult = ['SomeResultOne', 'SomeResultTwo'];
for (let i = 0; i < input.length; ++i) {
this.testInstanceMock.setup((_) => _.normalizeMap(input[i])).returns(() => expectedResult[i]);
}
const result = this.testInstance.normalizeMaps(input);
chai_1.assert.sameMembers(result, expectedResult);
}
normalizeMap__ItemWithNormalizedValues() {
const attributeValueOne = 'SomeValueOne';
const attributeValueTwo = 'SomeValueTwo';
const normalizedValueOne = 'SomeNormalizedValueOne';
const normalizedValueTwo = 'SomeNormalizedValueTwo';
const input = { SomePropertyOne: attributeValueOne, SomePropertyTwo: attributeValueTwo };
this.testInstanceMock.setup((_) => _.normalizeAttributeValue(attributeValueOne)).returns(() => normalizedValueOne);
this.testInstanceMock.setup((_) => _.normalizeAttributeValue(attributeValueTwo)).returns(() => normalizedValueTwo);
const result = this.testInstance.normalizeMap(input);
chai_1.assert.deepEqual(result, { SomePropertyOne: normalizedValueOne, SomePropertyTwo: normalizedValueTwo });
}
normalizeAttributeValue_S_StringValue() {
const value = 'SomeValue';
const input = { S: value };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.equal(result, value);
}
normalizeAttributeValue_S_StringEmpty() {
const value = '';
const input = { S: value };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.equal(result, value);
}
normalizeAttributeValue_N_NumberValue() {
const value = 123.45;
const input = { N: `${value}` };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.equal(result, value);
}
normalizeAttributeValue_N_NumberZero() {
const value = 0;
const input = { N: `${value}` };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.equal(result, value);
}
normalizeAttributeValue_SS_StringArray() {
const value = ['SomeString', 'SomeOtherString'];
const input = { SS: value };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_SS_StringArrayEmpty() {
const value = [];
const input = { SS: value };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_SS_StringArrayValuesEmpty() {
const value = ['', ''];
const input = { SS: value };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_SS_StringArrayValuesPartialEmpty() {
const value = ['', 'Piet'];
const input = { SS: value };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_NS_NumberArray() {
const value = [123.45, 234.56];
const input = { NS: value.map((_) => `${_}`) };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_NS_NumberArrayEmpty() {
const value = [];
const input = { NS: value.map((_) => `${_}`) };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_NS_NumberArrayValuesZero() {
const value = [0, 0];
const input = { NS: value.map((_) => `${_}`) };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_NULL_null() {
const input = { NULL: true };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.isNull(result);
}
normalizeAttributeValue_BoolTrue_True() {
const input = { BOOL: true };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.isTrue(result);
}
normalizeAttributeValue_BoolFalse_False() {
const input = { BOOL: false };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.isFalse(result);
}
normalizeAttributeValue_M_NormalizedMap() {
const value = 'SomeValue';
const normalizedValue = 'SomeNormalizedValue';
const input = { M: value };
this.testInstanceMock.setup((_) => _.normalizeMap(Moq.It.isAny())).returns(() => normalizedValue);
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.equal(result, normalizedValue);
this.testInstanceMock.verify((_) => _.normalizeMap(value), Moq.Times.once());
}
normalizeAttributeValue_L_ValuesList() {
const value = [118.56, 'Piet', null];
const input = { L: [{ N: '118.56' }, { S: 'Piet' }, { NULL: true }] };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_L_EmptyList() {
const value = [];
const input = { L: [] };
const result = this.testInstance.normalizeAttributeValue(input);
chai_1.assert.sameMembers(result, value);
}
normalizeAttributeValue_Other_Error() {
let caught = false;
try {
this.testInstance.normalizeAttributeValue({ B: '' });
}
catch (e) {
caught = true;
}
chai_1.assert.isTrue(caught);
}
};
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeMaps__NormalizedMaps", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeMap__ItemWithNormalizedValues", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_S_StringValue", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_S_StringEmpty", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_N_NumberValue", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_N_NumberZero", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_SS_StringArray", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_SS_StringArrayEmpty", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_SS_StringArrayValuesEmpty", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_SS_StringArrayValuesPartialEmpty", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_NS_NumberArray", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_NS_NumberArrayEmpty", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_NS_NumberArrayValuesZero", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_NULL_null", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_BoolTrue_True", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_BoolFalse_False", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_M_NormalizedMap", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_L_ValuesList", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_L_EmptyList", null);
__decorate([
mocha_1.test
], AttributeMapNormalizerTest.prototype, "normalizeAttributeValue_Other_Error", null);
AttributeMapNormalizerTest = __decorate([
mocha_1.suite
], AttributeMapNormalizerTest);
//# sourceMappingURL=attribute-map-normalizer.test.js.map