-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed pythonic boolean. * type = module to make imports work. * Unit tests for stuff in lib.
- Loading branch information
1 parent
a65d857
commit 469746b
Showing
6 changed files
with
213 additions
and
2 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,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); | ||
}); |