Skip to content

Commit

Permalink
Adding test to ensure querying for hash key with range key index works
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Apr 8, 2020
1 parent 2cba45c commit c712249
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,23 @@ describe("Query", () => {
});
});

it("Should send correct request on query.exec for index with hash and range key but only querying hash key", async () => {
Model = new dynamoose.Model("Cat", {"id": Number, "age": {"type": Number, "index": {"global": true, "rangeKey": "name"}}, "name": String});
queryPromiseResolver = () => ({"Items": []});
await callType.func(Model.query("age").eq(1).exec).bind(Model.query("age").eq(1))();
expect(queryParams).to.eql({
"TableName": "Cat",
"IndexName": "ageGlobalIndex",
"ExpressionAttributeNames": {
"#qha": "age"
},
"ExpressionAttributeValues": {
":qhv": {"N": "1"}
},
"KeyConditionExpression": "#qha = :qhv"
});
});

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

0 comments on commit c712249

Please sign in to comment.