Skip to content

Commit

Permalink
Adding tests to ensure Model.update with rangeKey works correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed May 8, 2020
1 parent dde7426 commit 05100c9
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions test/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,34 @@ describe("Model", () => {
});
});

it("Should send correct params to updateItem for single object update with rangeKey", async () => {
updateItemFunction = () => Promise.resolve({});
User = dynamoose.model("User", {"pk": Number, "sk": {"type": Number, "rangeKey": true}, "name": String, "age": Number});
await callType.func(User).bind(User)({"pk": 1, "sk": 1, "name": "Charlie"});
expect(updateItemParams).to.be.an("object");
expect(updateItemParams).to.eql({
"ExpressionAttributeNames": {
"#a0": "name"
},
"ExpressionAttributeValues": {
":v0": {
"S": "Charlie"
}
},
"UpdateExpression": "SET #a0 = :v0",
"Key": {
"pk": {
"N": "1"
},
"sk": {
"N": "1"
}
},
"TableName": "User",
"ReturnValues": "ALL_NEW"
});
});

it("Should send correct params to updateItem for single object update with multiple updates", async () => {
updateItemFunction = () => Promise.resolve({});
await callType.func(User).bind(User)({"id": 1, "name": "Charlie", "age": 5});
Expand Down Expand Up @@ -2140,6 +2168,38 @@ describe("Model", () => {
});
});

it("Should send correct params to updateItem for single object update with multiple updates with rangeKey", async () => {
updateItemFunction = () => Promise.resolve({});
User = dynamoose.model("User", {"pk": Number, "sk": {"type": Number, "rangeKey": true}, "name": String, "age": Number});
await callType.func(User).bind(User)({"pk": 1, "sk": 1, "name": "Charlie", "age": 5});
expect(updateItemParams).to.be.an("object");
expect(updateItemParams).to.eql({
"ExpressionAttributeNames": {
"#a0": "name",
"#a1": "age"
},
"ExpressionAttributeValues": {
":v0": {
"S": "Charlie"
},
":v1": {
"N": "5"
}
},
"UpdateExpression": "SET #a0 = :v0, #a1 = :v1",
"Key": {
"pk": {
"N": "1"
},
"sk": {
"N": "1"
}
},
"TableName": "User",
"ReturnValues": "ALL_NEW"
});
});

it("Should send correct params to updateItem with seperate key and update objects", async () => {
updateItemFunction = () => Promise.resolve({});
await callType.func(User).bind(User)({"id": 1}, {"name": "Charlie"});
Expand All @@ -2164,6 +2224,34 @@ describe("Model", () => {
});
});

it("Should send correct params to updateItem with seperate key and update objects with rangeKey", async () => {
updateItemFunction = () => Promise.resolve({});
User = dynamoose.model("User", {"pk": Number, "sk": {"type": Number, "rangeKey": true}, "name": String, "age": Number});
await callType.func(User).bind(User)({"pk": 1, "sk": 1}, {"name": "Charlie"});
expect(updateItemParams).to.be.an("object");
expect(updateItemParams).to.eql({
"ExpressionAttributeNames": {
"#a0": "name"
},
"ExpressionAttributeValues": {
":v0": {
"S": "Charlie"
}
},
"UpdateExpression": "SET #a0 = :v0",
"Key": {
"pk": {
"N": "1"
},
"sk": {
"N": "1"
}
},
"TableName": "User",
"ReturnValues": "ALL_NEW"
});
});

it("Should send correct params to updateItem with seperate key and update objects and multiple updates", async () => {
updateItemFunction = () => Promise.resolve({});
await callType.func(User).bind(User)({"id": 1}, {"name": "Charlie", "age": 5});
Expand Down Expand Up @@ -2192,6 +2280,38 @@ describe("Model", () => {
});
});

it("Should send correct params to updateItem with seperate key and update objects and multiple updates with rangeKey", async () => {
updateItemFunction = () => Promise.resolve({});
User = dynamoose.model("User", {"pk": Number, "sk": {"type": Number, "rangeKey": true}, "name": String, "age": Number});
await callType.func(User).bind(User)({"pk": 1, "sk": 1}, {"name": "Charlie", "age": 5});
expect(updateItemParams).to.be.an("object");
expect(updateItemParams).to.eql({
"ExpressionAttributeNames": {
"#a0": "name",
"#a1": "age"
},
"ExpressionAttributeValues": {
":v0": {
"S": "Charlie"
},
":v1": {
"N": "5"
}
},
"UpdateExpression": "SET #a0 = :v0, #a1 = :v1",
"Key": {
"pk": {
"N": "1"
},
"sk": {
"N": "1"
}
},
"TableName": "User",
"ReturnValues": "ALL_NEW"
});
});

it("Should send correct params to updateItem when using undefined to restore to default property", async () => {
updateItemFunction = () => Promise.resolve({});
User = dynamoose.model("User", {"id": Number, "name": {"type": String, "default": () => "Charlie"}, "age": Number});
Expand Down

1 comment on commit 05100c9

@vercel
Copy link

@vercel vercel bot commented on 05100c9 May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment failed with the following error:

The most recent charge for your active payment method has failed. Please update it here: https://zeit.co/teams/dynamoose/settings/billing

Please sign in to comment.