-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from stofolus/separate-validation-from-mock-dat…
…a-fetch Separate validation from mock data fetch
- Loading branch information
Showing
7 changed files
with
73 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const FileMockDataReader = require("./fileMockDataReader"); | ||
|
||
describe("Validator", () => { | ||
const fileContent = ["Testpersonnummer", "201710022383", "201801202381"].join( | ||
"\r\n" | ||
); | ||
|
||
beforeEach(() => { | ||
const mockFs = { | ||
readdirSync: jest.fn(() => ["/some-path"]), | ||
readFileSync: jest.fn(data => fileContent) | ||
}; | ||
jest.mock("fs", () => mockFs); | ||
}); | ||
|
||
describe("fetch()", () => { | ||
test("returns a list of pnrs", () => { | ||
expect(FileMockDataReader.fetch()).toEqual( | ||
expect.arrayContaining(["201801202381", "201710022383"]) | ||
); | ||
}); | ||
test("can filter out non-pnr lines from mock data", () => { | ||
expect(FileMockDataReader.fetch()).not.toContain("Testpersonnummer"); | ||
}); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,13 @@ | ||
const Pnr = require(`./pnr`); | ||
|
||
class Validator { | ||
constructor(testPnrs) { | ||
this.testPnrs = testPnrs; | ||
} | ||
|
||
isMock(pnr) { | ||
return this.testPnrs.includes(Pnr.normalizePnr(pnr)); | ||
} | ||
} | ||
|
||
module.exports = Validator; |
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,20 @@ | ||
const Validator = require("./validator"); | ||
|
||
describe("Validator", () => { | ||
let validator; | ||
|
||
beforeEach(() => { | ||
validator = new Validator(["1", "2"]); | ||
}); | ||
|
||
describe("isMock()", () => { | ||
test("returns true if pnr is in mock data", () => { | ||
expect(validator.isMock("1")).toBeTruthy(); | ||
expect(validator.isMock("2")).toBeTruthy(); | ||
}); | ||
|
||
test("returns false if pnr is not in mock data", () => { | ||
expect(validator.isMock("3")).toBeFalsy(); | ||
}); | ||
}); | ||
}); |