Skip to content

Commit

Permalink
Updating tests to ensure expressions don’t include -
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Apr 16, 2020
1 parent 7ccd64e commit 9900a86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions test/Condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ describe("Condition", () => {
},
{
"input": () => new Condition().where("name").in(["Charlie", "Bob"]),
"output": {"ConditionExpression": "#a0 IN (:v0-1, :v0-2)", "ExpressionAttributeNames": {"#a0": "name"}, "ExpressionAttributeValues": {":v0-1": {"S": "Charlie"}, ":v0-2": {"S": "Bob"}}}
"output": {"ConditionExpression": "#a0 IN (:v0_1, :v0_2)", "ExpressionAttributeNames": {"#a0": "name"}, "ExpressionAttributeValues": {":v0_1": {"S": "Charlie"}, ":v0_2": {"S": "Bob"}}}
},
{
"input": () => new Condition().where("name").not().in(["Charlie", "Bob"]),
"error": "IN can not follow not()"
},
{
"input": () => new Condition().where("age").between(13, 18),
"output": {"ConditionExpression": "#a0 BETWEEN :v0-1 AND :v0-2", "ExpressionAttributeNames": {"#a0": "age"}, "ExpressionAttributeValues": {":v0-1": {"N": "13"}, ":v0-2": {"N": "18"}}}
"output": {"ConditionExpression": "#a0 BETWEEN :v0_1 AND :v0_2", "ExpressionAttributeNames": {"#a0": "age"}, "ExpressionAttributeValues": {":v0_1": {"N": "13"}, ":v0_2": {"N": "18"}}}
},
{
"input": () => new Condition().where("age").not().between(13, 18),
Expand Down
29 changes: 18 additions & 11 deletions test/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,21 @@ describe("Query", () => {
},
"ExpressionAttributeValues": {
":qhv": {"S": "Charlie"},
":v1-1": {"N": "1"},
":v1-2": {"N": "3"}
":v1_1": {"N": "1"},
":v1_2": {"N": "3"}
},
"FilterExpression": "#a1 BETWEEN :v1-1 AND :v1-2",
"FilterExpression": "#a1 BETWEEN :v1_1 AND :v1_2",
"KeyConditionExpression": "#qha = :qhv"
});
});

it("Should not include - in filter expression", async () => {
queryPromiseResolver = () => ({"Items": []});
const query = Model.query("name").eq("Charlie").filter("id").between(1, 3);
await callType.func(query.exec).bind(query)();
expect(queryParams.FilterExpression).to.not.include("-");
});

it("Should send correct request on query.exec with query condition", async () => {
queryPromiseResolver = () => ({"Items": []});
Model = new dynamoose.Model("Cat", {"id": Number, "name": {"type": String, "index": {"global": true, "rangeKey": "age"}}, "age": Number});
Expand Down Expand Up @@ -835,10 +842,10 @@ describe("Query", () => {
},
"ExpressionAttributeValues": {
":qhv": {"S": "Charlie"},
":v1-1": {"N": "10"},
":v1-2": {"N": "20"}
":v1_1": {"N": "10"},
":v1_2": {"N": "20"}
},
"FilterExpression": "#a1 IN (:v1-1, :v1-2)",
"FilterExpression": "#a1 IN (:v1_1, :v1_2)",
"KeyConditionExpression": "#qha = :qhv"
});
});
Expand All @@ -855,12 +862,12 @@ describe("Query", () => {
},
"ExpressionAttributeValues": {
":qhv": {"S": "Charlie"},
":v1-1": {"N": "10"},
":v1-2": {"N": "20"},
":v1-3": {"N": "30"},
":v1-4": {"N": "40"}
":v1_1": {"N": "10"},
":v1_2": {"N": "20"},
":v1_3": {"N": "30"},
":v1_4": {"N": "40"}
},
"FilterExpression": "#a1 IN (:v1-1, :v1-2, :v1-3, :v1-4)",
"FilterExpression": "#a1 IN (:v1_1, :v1_2, :v1_3, :v1_4)",
"KeyConditionExpression": "#qha = :qhv"
});
});
Expand Down
13 changes: 10 additions & 3 deletions test/Scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,21 @@ describe("Scan", () => {
"#a0": "id"
},
"ExpressionAttributeValues": {
":v0-1": {"N": "1"},
":v0-2": {"N": "3"}
":v0_1": {"N": "1"},
":v0_2": {"N": "3"}
},
"FilterExpression": "#a0 BETWEEN :v0-1 AND :v0-2",
"FilterExpression": "#a0 BETWEEN :v0_1 AND :v0_2",
"TableName": "Cat"
});
});

it("Should not include - in filter expression", async () => {
scanPromiseResolver = () => ({"Items": []});
const scan = Model.scan().filter("id").between(1, 3);
await callType.func(scan.exec).bind(scan)();
expect(scanParams.FilterExpression).to.not.include("-");
});

it("Should return correct result for get function on attribute", async () => {
Model = new dynamoose.Model("Cat", new dynamoose.Schema({"id": Number, "name": {"type": String, "get": (val) => `${val}-get`}}));
scanPromiseResolver = () => ({"Items": [{"id": {"N": "1"}, "name": {"S": "Charlie"}}]});
Expand Down

0 comments on commit 9900a86

Please sign in to comment.