-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INTERNAL] Rework ReaderFilter to accept a simple filter callback
- Loading branch information
1 parent
b4a20db
commit b3993d8
Showing
3 changed files
with
76 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const test = require("ava"); | ||
const sinon = require("sinon"); | ||
const ReaderFilter = require("../../lib/ReaderFilter"); | ||
|
||
test("_byGlob: Basic filter", async (t) => { | ||
const abstractReader = { | ||
_byGlob: sinon.stub().returns(Promise.resolve(["resource a", "resource b"])) | ||
}; | ||
const trace = { | ||
collection: sinon.spy() | ||
}; | ||
const readerCollection = new ReaderFilter({ | ||
reader: abstractReader, | ||
filterCallback: function(resource) { | ||
if (resource === "resource a") { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}); | ||
|
||
const resources = await readerCollection._byGlob("anyPattern", {}, trace); | ||
t.deepEqual(resources, ["resource b"], "Correct resource in result"); | ||
}); | ||
|
||
test("_byPath: Negative filter", async (t) => { | ||
const abstractReader = { | ||
_byPath: sinon.stub().returns(Promise.resolve("resource a")) | ||
}; | ||
const trace = { | ||
collection: sinon.spy() | ||
}; | ||
const readerCollection = new ReaderFilter({ | ||
reader: abstractReader, | ||
filterCallback: function(resource) { | ||
if (resource === "resource a") { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}); | ||
|
||
const resources = await readerCollection._byPath("anyPattern", {}, trace); | ||
t.deepEqual(resources, null, "Correct empty in result"); | ||
}); | ||
|
||
test("_byPath: Positive filter", async (t) => { | ||
const abstractReader = { | ||
_byPath: sinon.stub().returns(Promise.resolve("resource b")) | ||
}; | ||
const trace = { | ||
collection: sinon.spy() | ||
}; | ||
const readerCollection = new ReaderFilter({ | ||
reader: abstractReader, | ||
filterCallback: function(resource) { | ||
if (resource === "resource a") { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}); | ||
|
||
const resources = await readerCollection._byPath("anyPattern", {}, trace); | ||
t.deepEqual(resources, "resource b", "Correct resource in result"); | ||
}); |