Skip to content

Commit

Permalink
Merge pull request #737 from dynamoosejs/emptyDocumentInitializer
Browse files Browse the repository at this point in the history
Empty document initializer bug
  • Loading branch information
fishcharlie committed Mar 20, 2020
2 parents d183fd8 + fea80b7 commit 8125962
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function DocumentCarrier(model) {

// Document represents an item in a Model that is either pending (not saved) or saved
class Document {
constructor(object, settings = {}) {
constructor(object = {}, settings = {}) {
const documentObject = Document.isDynamoObject(object) ? aws.converter().unmarshall({...object}) : object;
Object.keys(documentObject).forEach((key) => this[key] = documentObject[key]);
this[internalProperties] = {};
Expand Down
13 changes: 13 additions & 0 deletions test/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,19 @@ describe("Document", () => {
}]);
});

it("Should work correctly if attributes added to document after initalization", async () => {
putItemFunction = () => Promise.resolve();
User = new Model("User", {"id": Number, "name": String}, {"create": false, "waitForActive": false});
user = new User();
user.id = 1;
user.name = "Charlie";
await callType.func(user).bind(user)();
expect(putParams).to.eql([{
"Item": {"id": {"N": "1"}, "name": {"S": "Charlie"}},
"TableName": "User"
}]);
});

it("Should throw error if object contains properties that have type mismatch with schema", () => {
putItemFunction = () => Promise.resolve();
User = new Model("User", {"id": Number, "name": String, "age": Number}, {"create": false, "waitForActive": false});
Expand Down

0 comments on commit 8125962

Please sign in to comment.