Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement unwrap for lower-case type strings #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/AttributeValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ function unwrap1(dynamoData) {
if (keys.length !== 1)
throw new Error('Unexpected DynamoDB AttributeValue');
var typeStr = keys[0];
if (!unwrapFns.hasOwnProperty(typeStr))
var typeStrUpperCase = typeStr.toUpperCase();
if (!unwrapFns.hasOwnProperty(typeStrUpperCase))
throw errs.NoDatatype;
var val = dynamoData[typeStr];
return unwrapFns[typeStr] ? unwrapFns[typeStr](val) : val;
return unwrapFns[typeStrUpperCase] ? unwrapFns[typeStrUpperCase](val) : val;
}

/**
Expand Down
15 changes: 14 additions & 1 deletion tests/spec/AttributeValue.mockdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ module.exports = {
nothing1: { NULL: true }
},

obj2_lowercase_: {
key1: { s: 'str' },
key1a: { ss: [ 'str1', 'str2', 'str3' ] },
key2: { n: '1' },
key2a: { ns: [ '1.1', '1.2', '1.3' ] },

nothing1: { null: true }
},

obj3: {
bin: new Buffer('Hi')
},
Expand All @@ -95,7 +104,11 @@ module.exports = {
bin: {B: new Buffer('Hi')}
},

objInvalid_: {
obj3_lowercase_: {
bin: {b: new Buffer('Hi')}
},

objInvalid_: {
key1: { ABCD: 'str' }
},

Expand Down
9 changes: 9 additions & 0 deletions tests/spec/AttributeValue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ describe("AttributeValue", function() {
var obj1_ = mock.obj1_;
var obj2 = mock.obj2;
var obj2_ = mock.obj2_;
var obj2_lowercase_ = mock.obj2_lowercase_;
var obj3 = mock.obj3;
var obj3_ = mock.obj3_;
var obj3_lowercase_ = mock.obj3_lowercase_;
var objInvalid_ = mock.objInvalid_;
var singles = mock.singles;
var singles_ = mock.singles_;
Expand Down Expand Up @@ -59,6 +61,13 @@ describe("AttributeValue", function() {
expect(bufferEqual(binUnwrap, obj3.bin)).toBe(true);
});

it("Unwrap lowercase type strings", function() {
expect(_.isEqual(util.unwrap(obj2_lowercase_), obj2)).toBe(true);

var binUnwrap = util.unwrap(obj3_lowercase_).bin;
expect(bufferEqual(binUnwrap, obj3.bin)).toBe(true);
});

it("Unwrap singles", function() {
for (var i = 0; i < singles_.length; i++)
expect(_.isEqual(util.unwrap1(singles_[i]), singles[i])).toBe(true);
Expand Down