Skip to content

Commit

Permalink
Merge pull request #100 from yutak23/feature/fix-specialKeys-number
Browse files Browse the repository at this point in the history
fix: NUMBER_VALUE cannot be converted to String on specialKeys
  • Loading branch information
ca98am79 authored Nov 14, 2024
2 parents f2df74a + 25185cb commit c8be1cf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/connect-dynamodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ module.exports = function (connect) {
this.specialKeys.forEach((key) => {
if (typeof sess[key.name] !== "undefined") {
const item = {};
item[key.type] = sess[key.name];
item[key.type] = key.type === 'N' ? JSON.stringify(sess[key.name]) : sess[key.name];
params.Item[key.name] = item;
} else {
missingKeys.push(key.name);
Expand Down
38 changes: 38 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,44 @@ describe("DynamoDBStore", () => {
);
});
});

it("should store data correctly with specialKeys option", async () => {
const store = new DynamoDBStore({
client: client,
table: tableName,
specialKeys: [
{ name: 'number_field', type: 'N' }
]
});
const randomNum = Math.floor(Math.random() * 1000) + 1;

await new Promise((resolve, reject) => {
store.set(
sessionId,
{
cookie: {
maxAge: 2000,
},
number_field: randomNum,
},
(err) => {
if (err) return reject(err);
resolve();
}
);
});

return new Promise((resolve, reject) => {
store.get(sessionId, function (err, res) {
if (err) return reject(err);

res.cookie.should.eql({ maxAge: 2000 });
res.number_field.should.eql(randomNum);

resolve();
});
});
});
});

describe("Getting", () => {
Expand Down

0 comments on commit c8be1cf

Please sign in to comment.