Skip to content

Commit

Permalink
Merge 9ae809a into fdcc79a
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Mar 28, 2020
2 parents fdcc79a + 9ae809a commit 845e533
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Schema.js
Expand Up @@ -222,7 +222,7 @@ Schema.prototype.getAttributeTypeDetails = function(key, settings = {}) {

const action = (val) => {
if (typeSettings.storage === "seconds") {
return val.getTime() / 1000;
return Math.round(val.getTime() / 1000);
} else {
return val.getTime();
}
Expand Down
8 changes: 8 additions & 0 deletions test/Document.js
Expand Up @@ -559,6 +559,14 @@ describe("Document", () => {
expect(parseInt(putParams[0].Item.ttl.N)).to.be.within(expectedTTL - 1000, expectedTTL + 1000);
});

it("Should store whole number for expires", async () => {
putItemFunction = () => Promise.resolve();
User = new Model("User", new Schema({"id": Number, "name": String}), {"create": false, "waitForActive": false, "expires": 10000});
user = new User({"id": 1, "name": "Charlie", "ttl": new Date(1002)});
await callType.func(user).bind(user)();
expect(parseFloat(putParams[0].Item.ttl.N) % 1).to.eql(0);
});

it("Should save with correct object with expires set to object", async () => {
putItemFunction = () => Promise.resolve();
User = new Model("User", new Schema({"id": Number, "name": String}), {"create": false, "waitForActive": false, "expires": {"attribute": "expires", "ttl": 10000}});
Expand Down

0 comments on commit 845e533

Please sign in to comment.