Skip to content

Commit 83f6111

Browse files
Add more unit tests.
1 parent d68aac7 commit 83f6111

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5-
## [Unreleased]
5+
## [1.0.0] - 2015-05-29
66
### Added
77
- Add more validation on parameters.
88
- Add exclude filters.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-property-filter",
3-
"version": "0.0.9",
3+
"version": "1.0.0",
44
"keywords": ["json-property-filter", "filter", "json", "property", "path", "object", "element"],
55
"description": "A library to filter a JSON object by including/excluding properties.",
66
"main": "lib/jsonPropertyFilter.js",

test/jsonExcludePropertyFilter.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ describe("JsonExcludePropertyFilter", () => {
4343
it("should return the root properties of 'key2' property only", () => {
4444
let source = [];
4545
source["key1.key2"] = "value2";
46-
source["key1.key2.key3"] = "value3";
47-
source["key1.key2.key4"] = "value4";
46+
source["key1.key3.key4"] = "value3";
47+
source["key1.key3.key5"] = "value4";
4848
let expected = [];
4949
expected["key1.key2"] = "value2";
5050

51-
const filter = new JsonExcludePropertyFilter(["key1.key2.*"]);
51+
const filter = new JsonExcludePropertyFilter(["key1.key3.*"]);
5252
const filtered = filter.apply(source);
5353

5454
assert.deepEqual(filtered, expected);
@@ -69,4 +69,47 @@ describe("JsonExcludePropertyFilter", () => {
6969

7070
assert.deepEqual(filtered, expected);
7171
});
72+
73+
it("should return all properties of 'key3' property only", () => {
74+
let source = [];
75+
source["key1"] = "value1";
76+
source["key2"] = "value2";
77+
source["key3.key4"] = "value3";
78+
let expected = [];
79+
expected["key3.key4"] = "value3";
80+
81+
const filter = new JsonExcludePropertyFilter(["*"]);
82+
const filtered = filter.apply(source);
83+
84+
assert.deepEqual(filtered, expected);
85+
});
86+
87+
it("should return empty array", () => {
88+
let source = [];
89+
source["key1"] = "value";
90+
source["key2.key3.key4"] = "value3";
91+
source["key2.key3.key4"] = "value4";
92+
let expected = [];
93+
94+
const filter = new JsonExcludePropertyFilter(["**"]);
95+
const filtered = filter.apply(source);
96+
97+
assert.deepEqual(filtered, expected);
98+
});
99+
100+
it("should return original array", () => {
101+
let source = [];
102+
source["key1"] = "value1";
103+
source["key2"] = "value2";
104+
source["key3.key4"] = "value3";
105+
let expected = [];
106+
expected["key1"] = "value1";
107+
expected["key2"] = "value2";
108+
expected["key3.key4"] = "value3";
109+
110+
const filter = new JsonExcludePropertyFilter([]);
111+
const filtered = filter.apply(source);
112+
113+
assert.deepEqual(filtered, expected);
114+
});
72115
});

test/jsonPropertyFilter.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ describe("JsonPropertyFilter", () => {
126126

127127
assert.deepEqual(filtered, expected);
128128
});
129+
130+
it("should return the empty object", () => {
131+
const properties = ["**", "-**"];
132+
const filter = new JsonPropertyFilter(properties);
133+
const filtered = filter.apply(source);
134+
const expected = {};
135+
136+
assert.deepEqual(filtered, expected);
137+
});
138+
139+
it("should return the 'name' property only", () => {
140+
const properties = ["**", "-commit", "-protection", "-_links"];
141+
const filter = new JsonPropertyFilter(properties);
142+
const filtered = filter.apply(source);
143+
const expected = { name: "master" };
144+
145+
assert.deepEqual(filtered, expected);
146+
});
129147
});
130148

131149
describe("include", () => {

0 commit comments

Comments
 (0)