Skip to content

Commit d742c36

Browse files
Fix/query (#471)
* fixed the empty string inn the query Signed-off-by: Salman khan <[email protected]> * fixed the empty query Signed-off-by: Salman khan <[email protected]> * fixed the empty query Signed-off-by: Salman khan <[email protected]> * fixed the empty query Signed-off-by: Salman khan <[email protected]> --------- Signed-off-by: Salman khan <[email protected]>
1 parent ae34854 commit d742c36

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/implementation/Client/GRPCClient/state.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ export default class GRPCClientState implements IClientState {
248248
if (err) {
249249
return reject(err);
250250
}
251+
const resultsList = res.getResultsList();
252+
if (resultsList.length === 0) {
253+
return resolve({
254+
results: [],
255+
token: res.getToken(),
256+
} as StateQueryResponseType);
257+
}
251258

252259
// https://docs.dapr.io/reference/api/state_api/#response-body
253260
// map the res from gRPC

src/implementation/Client/HTTPClient/state.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export default class HTTPClientState implements IClientState {
103103
},
104104
});
105105

106+
if (result === "") {
107+
return { results: [] } as StateQueryResponseType;
108+
}
109+
106110
return result as StateQueryResponseType;
107111
}
108112
}

test/e2e/common/client.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,21 @@ describe("common/client", () => {
464464
await httpClient.state.delete(stateStoreMongoDbName, `key-${i}`);
465465
}
466466
});
467+
468+
it("should return an empty object when result is empty", async () => {
469+
const result = await httpClient.state.query(stateStoreMongoDbName, {
470+
filter: { EQ: { state: "statenotfound" } },
471+
sort: [
472+
{
473+
key: "state",
474+
order: "DESC",
475+
},
476+
],
477+
page: {
478+
limit: 10,
479+
},
480+
});
481+
expect(result).toEqual({ results: [] });
482+
});
467483
});
468484
});

0 commit comments

Comments
 (0)