Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from Giftbit/NewFilters_isNull_orNull
Browse files Browse the repository at this point in the history
Added `isNull` and `orNull` filter query params.
  • Loading branch information
Tim authored Nov 29, 2019
2 parents 64f94ca + c765e79 commit a86dab7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightrail-client",
"version": "4.3.0",
"version": "4.3.1",
"description": "A Javascript and Typescript client for Lightrail",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function request(method: string, path: string): superagent.Request {
}
if (!configuration.isBrowser) {
// TODO@Dan Review Previous import of package.json to dynamically set this was breaking publish (dist included src/ & package.json file)
r.set("User-Agent", "Lightrail-JavaScript/4.3.0");
r.set("User-Agent", "Lightrail-JavaScript/4.3.1");
}
if (configuration.isBrowser) {
r.set("X-Requested-With", "XMLHttpRequest");
Expand Down
4 changes: 3 additions & 1 deletion src/params/FilterableParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export interface FilterTypes {
eq: string | number; // Equal to (==). This is the default where no operator is specified
ne: string | number; // Not equal to (!=)
in: string | number; // Equals one of the members of a comma-separated list. Literal commas must be escaped (\,)
like: string; // Equal to with wildcard support. Percent signs (%) in the value are wild. This operator is only supported on string properties
like: string; // Equal to with wildcard support. Percent signs (%) in the value are wild. This operator is only supported on string properties
isNull: boolean; // Equal to null (true) or not equal to null (false).
orNull: boolean; // Allows other filters acting on the same property to also include results if the property is equal to null (true), or, not equal to null (false).
}

export type FilterableString = string | Partial<FilterTypes>;
Expand Down
33 changes: 33 additions & 0 deletions src/values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,39 @@ describe("values", () => {
chai.assert.isTrue(!!values.body.length);
});

it("gets values without endDate", async () => {
const values = await Lightrail.values.listValues({
endDate: {isNull: true}
});

chai.assert.isObject(values.body.find(v => v.endDate === null));
chai.assert.equal(values.body.filter(v => v.endDate != null).length, 0, `expected 0 results with a non-null endDate`);
});

it("can use orNull:true operator", async () => {
const values = await Lightrail.values.listValues({
endDate: {
lt: "1970-01-01", // no values have an endDate less than this day
orNull: true
}
});

chai.assert.isObject(values.body.find(v => v.endDate === null));
chai.assert.equal(values.body.filter(v => v.endDate !== null).length, 0, `expected 0 results with a non-null endDate`);
});

it("can use orNull:false operator", async () => {
const values = await Lightrail.values.listValues({
endDate: {
lt: "1970-01-01", // no values have an endDate less than this day
orNull: false
}
});

chai.assert.isObject(values.body.find(v => v.endDate !== null));
chai.assert.equal(values.body.filter(v => v.endDate === null).length, 0, `expected 0 results with a null endDate`);
});

it("gets values with a pagination limit", async () => {
const values = await Lightrail.values.listValues({limit: 1});

Expand Down

0 comments on commit a86dab7

Please sign in to comment.