From 952fb17418315ae47cce1f249e19c5010e5f4503 Mon Sep 17 00:00:00 2001 From: Matt Mazzola Date: Wed, 13 Jul 2016 12:57:25 -0700 Subject: [PATCH] Add isAdvancedFilter and isValidFilter functions with tests. --- src/models.ts | 8 ++++++++ test/models.spec.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/models.ts b/src/models.ts index b34d40b..2f801a8 100644 --- a/src/models.ts +++ b/src/models.ts @@ -159,6 +159,14 @@ export interface IAdvancedFilter extends IFilter { conditions: IAdvancedFilterCondition[]; } +export function isAdvancedFilter(filter: IFilter): Boolean { + return (filter.$schema === AdvancedFilter.schemaUrl); +} + +export function isValueFilter(filter: IFilter): Boolean { + return (filter.$schema === ValueFilter.schemaUrl); +} + export function isMeasure(arg: any): arg is IFilterMeasureTarget { return arg.table !== undefined && arg.measure !== undefined; } diff --git a/test/models.spec.ts b/test/models.spec.ts index edb6904..29cee0d 100644 --- a/test/models.spec.ts +++ b/test/models.spec.ts @@ -446,4 +446,37 @@ describe("Unit | Filters", function () { expect(errors).toBeUndefined(); }); }); + + describe('determine filter type', function () { + it('isValueFilter should return true for objects with matching shemaUrl and false otherwise', function () { + // Arrange + const testData = { + filter: new models.ValueFilter({ table: "a", column: "b" }, "In", ["x", "y"]), + nonFilter: {} + }; + + // Act + + // Assert + expect(models.isValueFilter(testData.filter.toJSON())).toBe(true); + expect(models.isValueFilter(testData.nonFilter)).toBe(false); + }); + + it('isAdvancedFilter should return true for objects with matching shemaUrl and false otherwise', function () { + // Arrange + const testData = { + filter: new models.AdvancedFilter({ table: "a", column: "b" }, "And", + { operator: "Contains", value: "x" }, + { operator: "Contains", value: "x" } + ), + nonFilter: {} + }; + + // Act + + // Assert + expect(models.isAdvancedFilter(testData.filter.toJSON())).toBe(true); + expect(models.isAdvancedFilter(testData.nonFilter)).toBe(false); + }); + }); }); \ No newline at end of file