mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 00:26:26 +00:00
fix: respect zero LinkedIn result limits (#76)
This commit is contained in:
@@ -55,7 +55,7 @@ export async function runSearch(opts: SearchOpts): Promise<number> {
|
|||||||
try {
|
try {
|
||||||
const html = await htmlFetch(buildUrl(opts))
|
const html = await htmlFetch(buildUrl(opts))
|
||||||
let cards = parseJobCards(html)
|
let cards = parseJobCards(html)
|
||||||
if (opts.limit && opts.limit > 0) cards = cards.slice(0, opts.limit)
|
if (opts.limit !== undefined && opts.limit >= 0) cards = cards.slice(0, opts.limit)
|
||||||
|
|
||||||
if (opts.format === "table") {
|
if (opts.format === "table") {
|
||||||
process.stdout.write(renderTable(cards) + "\n")
|
process.stdout.write(renderTable(cards) + "\n")
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { afterEach, describe, expect, test } from "bun:test";
|
||||||
|
import { runSearch } from "../src/commands/search";
|
||||||
|
|
||||||
|
const originalFetch = globalThis.fetch;
|
||||||
|
const originalStdoutWrite = process.stdout.write;
|
||||||
|
|
||||||
|
function searchCard(id: string, title: string): string {
|
||||||
|
return `<li>
|
||||||
|
<div data-entity-urn="urn:li:jobPosting:${id}">
|
||||||
|
<a class="base-card__full-link" href="https://www.linkedin.com/jobs/view/${id}"></a>
|
||||||
|
<h3 class="base-search-card__title">${title}</h3>
|
||||||
|
</div>
|
||||||
|
</li>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
globalThis.fetch = originalFetch;
|
||||||
|
process.stdout.write = originalStdoutWrite;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("runSearch", () => {
|
||||||
|
test("--limit 0 emits zero results", async () => {
|
||||||
|
globalThis.fetch = (async () => new Response(searchCard("123456", "Engineer"))) as typeof fetch;
|
||||||
|
|
||||||
|
let stdout = "";
|
||||||
|
process.stdout.write = ((chunk: string | Uint8Array) => {
|
||||||
|
stdout += chunk.toString();
|
||||||
|
return true;
|
||||||
|
}) as typeof process.stdout.write;
|
||||||
|
|
||||||
|
const code = await runSearch({
|
||||||
|
location: "Copenhagen, Denmark",
|
||||||
|
jobage: 9999,
|
||||||
|
page: 1,
|
||||||
|
limit: 0,
|
||||||
|
format: "json",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(code).toBe(0);
|
||||||
|
expect(JSON.parse(stdout).results).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user