-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests #78
Merged
Merged
Unit tests #78
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,74 @@ | ||
import test from "node:test"; | ||
import assert from "node:assert/strict"; | ||
import { | ||
fetchJurisdictionsData, | ||
fetchReporterData, | ||
fetchVolumesData, | ||
fetchCasesList, | ||
fetchCaselawBody, | ||
fetchCaseMetadata, | ||
getBreadcrumbLinks, | ||
} from "./data.js"; | ||
|
||
global.window = { BUCKET_ROOT: "https://cap-redacted-demo.lil.tools" }; | ||
|
||
test("fetchJurisdictionsData fetches jurisdictions ", async (t) => { | ||
await fetchJurisdictionsData((data) => { | ||
assert.ok(data instanceof Object); | ||
assert.ok(Object.keys(data).length > 3); | ||
assert.ok(Object.keys(data).includes("Arkansas")); | ||
}); | ||
}); | ||
|
||
test("fetchReporterData can fetch metadata for a reporter", async (t) => { | ||
await fetchReporterData("ark", (data) => { | ||
assert.ok(data instanceof Object); | ||
assert.strictEqual(data.slug, "ark"); | ||
}); | ||
}); | ||
|
||
test("fetchVolumeData can fetch a list of volumes", async (t) => { | ||
await fetchVolumesData("ark", (data) => { | ||
assert.ok(data instanceof Array); | ||
assert.ok(data.length > 100); | ||
}); | ||
}); | ||
|
||
test("fetchCasesList can load a list of cases", async (t) => { | ||
await fetchCasesList("ark", "1", (data) => { | ||
assert.ok(data instanceof Array); | ||
assert.ok(data.length > 50); | ||
}); | ||
}); | ||
|
||
test("fetchCaselawBody can load a case html file", async (t) => { | ||
await fetchCaselawBody("ark", "1", "0011-01", (data) => { | ||
// literal strings arent instances of String, so we have to use typeof | ||
assert.strictEqual(typeof data, "string"); | ||
assert.match(data, /<section/); | ||
}); | ||
}); | ||
|
||
test("fetchCaseMetadata can load a case metadata file", async (t) => { | ||
await fetchCaseMetadata("ark", "1", "0011-01", (data) => { | ||
assert.ok(data instanceof Object); | ||
assert.strictEqual(data.name, "Goings against Mills"); | ||
}); | ||
}); | ||
|
||
test("getBreadcrumbLinks", async (t) => { | ||
const reporterData = { | ||
slug: "ark", | ||
short_name: "Arkansas", | ||
}; | ||
const volume = "1"; | ||
const expected = [ | ||
{ | ||
url: "/caselaw/?reporter=ark", | ||
name: "Reporter Arkansas", | ||
}, | ||
{ url: "/caselaw/?reporter=ark&volume=1", name: "Volume 1" }, | ||
]; | ||
const links = getBreadcrumbLinks(reporterData, volume); | ||
assert.deepStrictEqual(links, expected); | ||
}); |
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,38 @@ | ||
import { test, before } from "node:test"; | ||
import assert from "node:assert/strict"; | ||
|
||
import { fetchOr404 } from "./fetchOr404.js"; | ||
|
||
let newLocation = ""; | ||
|
||
const window = { | ||
location: { | ||
replace: function (url) { | ||
newLocation = url; | ||
}, | ||
search: "foo", | ||
}, | ||
}; | ||
|
||
global.window = window; | ||
global.location = window.location; | ||
|
||
before(() => (newLocation = "")); | ||
|
||
test("fetchOr404 works when the fetches work.", async (t) => { | ||
const fetches = [ | ||
() => Promise.resolve("first fetch"), | ||
() => Promise.resolve("second fetch"), | ||
]; | ||
await fetchOr404(...fetches); | ||
assert.strictEqual(newLocation, ""); | ||
}); | ||
|
||
test("fetchOr404 redirects when a fetch fails.", async (t) => { | ||
const fetches = [ | ||
() => Promise.resolve("first fetch"), | ||
() => Promise.reject("second fetch"), | ||
]; | ||
await fetchOr404(...fetches); | ||
assert.equal(newLocation, "./not-found/foo"); | ||
}); |
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,81 @@ | ||
import { test } from "node:test"; | ||
import assert from "node:assert/strict"; | ||
|
||
import { isEmpty } from "./isEmpty.js"; | ||
|
||
test("isEmpty returns true for empty objects", (t) => { | ||
const emptyObj = {}; | ||
assert(isEmpty(emptyObj)); | ||
}); | ||
|
||
test("isEmpty returns true for empty arrays", (t) => { | ||
const emptyArray = []; | ||
assert.ok(isEmpty(emptyArray)); | ||
}); | ||
|
||
test("isEmpty returns true for empty strings", (t) => { | ||
const emptyString = ""; | ||
assert.ok(isEmpty(emptyString)); | ||
}); | ||
|
||
test("isEmpty returns false for non-empty objects", (t) => { | ||
const nonEmptyObj = { a: 1 }; | ||
assert.ok(!isEmpty(nonEmptyObj)); | ||
}); | ||
|
||
test("isEmpty returns false for non-empty arrays", (t) => { | ||
const nonEmptyArray = [1]; | ||
assert.ok(!isEmpty(nonEmptyArray)); | ||
}); | ||
|
||
test("isEmpty returns false for non-empty strings", (t) => { | ||
const nonEmptyString = "a"; | ||
assert.ok(!isEmpty(nonEmptyString)); | ||
}); | ||
|
||
test("isEmpty returns false for null", (t) => { | ||
assert.ok(isEmpty(null)); | ||
}); | ||
|
||
test("isEmpty throws for unsupported types", (t) => { | ||
assert.throws( | ||
() => { | ||
isEmpty(true); | ||
}, | ||
{ | ||
message: "Unsuported type: boolean", | ||
}, | ||
); | ||
assert.throws( | ||
() => { | ||
isEmpty(1); | ||
}, | ||
{ | ||
message: "Unsuported type: number", | ||
}, | ||
); | ||
assert.throws( | ||
() => { | ||
isEmpty(BigInt(9007199254740991)); | ||
}, | ||
{ | ||
message: "Unsuported type: bigint", | ||
}, | ||
); | ||
assert.throws( | ||
() => { | ||
isEmpty(Symbol("foo")); | ||
}, | ||
{ | ||
message: "Unsuported type: symbol", | ||
}, | ||
); | ||
assert.throws( | ||
() => { | ||
isEmpty(() => {}); | ||
}, | ||
{ | ||
message: "Unsuported type: function", | ||
}, | ||
); | ||
}); |
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,16 @@ | ||
import { test } from "node:test"; | ||
import assert from "node:assert/strict"; | ||
|
||
import { slugify } from "./slugify.js"; | ||
|
||
test("slugify replaces spaces with hyphens", (t) => { | ||
const actual = slugify("hello world"); | ||
const expected = "hello-world"; | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
test("slugify replaces special characters with empty strings", (t) => { | ||
const actual = slugify("hello!@#$%^&*()"); | ||
const expected = "hello"; | ||
assert.equal(actual, expected); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh dear, I am such a python programmer.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and I missed a typo!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crap, I'll put up another PR!