@zonuexe/techbook-mcp 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/README.md +39 -20
  3. package/dist/adapters/publishers/google-books.d.ts +4 -0
  4. package/dist/adapters/publishers/google-books.d.ts.map +1 -0
  5. package/dist/adapters/publishers/google-books.js +75 -0
  6. package/dist/adapters/publishers/google-books.js.map +1 -0
  7. package/dist/adapters/publishers/isbn-publisher-codes.d.ts +21 -0
  8. package/dist/adapters/publishers/isbn-publisher-codes.d.ts.map +1 -0
  9. package/dist/adapters/publishers/isbn-publisher-codes.js +49 -0
  10. package/dist/adapters/publishers/isbn-publisher-codes.js.map +1 -0
  11. package/dist/adapters/publishers/juse-p.d.ts +3 -0
  12. package/dist/adapters/publishers/juse-p.d.ts.map +1 -0
  13. package/dist/adapters/publishers/juse-p.js +110 -0
  14. package/dist/adapters/publishers/juse-p.js.map +1 -0
  15. package/dist/adapters/publishers/registry.d.ts.map +1 -1
  16. package/dist/adapters/publishers/registry.js +4 -0
  17. package/dist/adapters/publishers/registry.js.map +1 -1
  18. package/dist/application/get-book-by-isbn.d.ts +3 -2
  19. package/dist/application/get-book-by-isbn.d.ts.map +1 -1
  20. package/dist/application/get-book-by-isbn.js +22 -3
  21. package/dist/application/get-book-by-isbn.js.map +1 -1
  22. package/dist/config/credentials.d.ts +8 -0
  23. package/dist/config/credentials.d.ts.map +1 -0
  24. package/dist/config/credentials.js +32 -0
  25. package/dist/config/credentials.js.map +1 -0
  26. package/dist/main.js +15 -1
  27. package/dist/main.js.map +1 -1
  28. package/dist/setup.d.ts +2 -0
  29. package/dist/setup.d.ts.map +1 -0
  30. package/dist/setup.js +43 -0
  31. package/dist/setup.js.map +1 -0
  32. package/flake.lock +61 -0
  33. package/package.json +1 -1
  34. package/.claude/settings.local.json +0 -38
  35. package/.codex/skills/techbook-mcp-release-prep/SKILL.md +0 -105
  36. package/.github/workflows/test.yml +0 -72
  37. package/.oxlintrc.json +0 -12
  38. package/AGENTS.md +0 -100
  39. package/deno.json +0 -3
  40. package/src/adapters/cache/memory-cache.ts +0 -31
  41. package/src/adapters/cache/null-cache.ts +0 -8
  42. package/src/adapters/calil.ts +0 -57
  43. package/src/adapters/html/cheerio-parser.ts +0 -50
  44. package/src/adapters/http/fetch-client.ts +0 -47
  45. package/src/adapters/http/mock-client.ts +0 -77
  46. package/src/adapters/openbd.ts +0 -142
  47. package/src/adapters/publishers/base.ts +0 -279
  48. package/src/adapters/publishers/book-tech.ts +0 -117
  49. package/src/adapters/publishers/born-digital.ts +0 -143
  50. package/src/adapters/publishers/coronasha.ts +0 -139
  51. package/src/adapters/publishers/gihyo.ts +0 -120
  52. package/src/adapters/publishers/impress.ts +0 -103
  53. package/src/adapters/publishers/lambdanote.ts +0 -146
  54. package/src/adapters/publishers/manatee.ts +0 -113
  55. package/src/adapters/publishers/maruzen-publishing.ts +0 -129
  56. package/src/adapters/publishers/optronics.ts +0 -113
  57. package/src/adapters/publishers/oreilly-japan.ts +0 -133
  58. package/src/adapters/publishers/peaks.ts +0 -98
  59. package/src/adapters/publishers/personal-media.ts +0 -168
  60. package/src/adapters/publishers/registry.ts +0 -38
  61. package/src/adapters/publishers/rutles.ts +0 -149
  62. package/src/adapters/publishers/saiensu.ts +0 -136
  63. package/src/adapters/publishers/seshop.ts +0 -121
  64. package/src/adapters/publishers/tatsu-zine.ts +0 -142
  65. package/src/adapters/publishers/techbookfest.ts +0 -179
  66. package/src/application/get-book-by-isbn.ts +0 -50
  67. package/src/application/get-book-detail.ts +0 -40
  68. package/src/application/search-books.ts +0 -64
  69. package/src/domain/book.ts +0 -35
  70. package/src/domain/publisher.ts +0 -18
  71. package/src/main.ts +0 -14
  72. package/src/mcp/server.ts +0 -113
  73. package/src/mcp/tools.ts +0 -71
  74. package/src/ports/cache.ts +0 -5
  75. package/src/ports/html-parser.ts +0 -15
  76. package/src/ports/http.ts +0 -17
  77. package/tests/fixtures/book-tech-detail.html +0 -51
  78. package/tests/fixtures/book-tech-search.html +0 -91
  79. package/tests/fixtures/born-digital-detail.html +0 -62
  80. package/tests/fixtures/born-digital-search.html +0 -51
  81. package/tests/fixtures/calil-book.html +0 -987
  82. package/tests/fixtures/coronasha-detail.html +0 -41
  83. package/tests/fixtures/coronasha-search.html +0 -61
  84. package/tests/fixtures/gihyo-detail.html +0 -42
  85. package/tests/fixtures/gihyo-search.json +0 -54
  86. package/tests/fixtures/impress-detail-epub.html +0 -746
  87. package/tests/fixtures/impress-detail-social.html +0 -689
  88. package/tests/fixtures/lambdanote-search.html +0 -66
  89. package/tests/fixtures/manatee-detail.html +0 -53
  90. package/tests/fixtures/manatee-search.html +0 -59
  91. package/tests/fixtures/maruzen-detail.html +0 -51
  92. package/tests/fixtures/maruzen-search.html +0 -60
  93. package/tests/fixtures/openbd-response.json +0 -110
  94. package/tests/fixtures/optronics-detail.html +0 -30
  95. package/tests/fixtures/optronics-search.html +0 -75
  96. package/tests/fixtures/oreilly-detail.html +0 -52
  97. package/tests/fixtures/oreilly-ebook-list.html +0 -53
  98. package/tests/fixtures/peaks-detail.html +0 -39
  99. package/tests/fixtures/peaks-top.html +0 -50
  100. package/tests/fixtures/personal-media-detail.html +0 -32
  101. package/tests/fixtures/personal-media-search.html +0 -39
  102. package/tests/fixtures/rutles-detail.html +0 -32
  103. package/tests/fixtures/rutles-search.html +0 -62
  104. package/tests/fixtures/saiensu-detail.html +0 -41
  105. package/tests/fixtures/saiensu-search.html +0 -65
  106. package/tests/fixtures/seshop-detail.html +0 -45
  107. package/tests/fixtures/seshop-search.html +0 -58
  108. package/tests/fixtures/tatsu-zine-detail-free.html +0 -24
  109. package/tests/fixtures/tatsu-zine-search.html +0 -40
  110. package/tests/fixtures/techbookfest-search.json +0 -73
  111. package/tests/unit/adapters/base.test.ts +0 -441
  112. package/tests/unit/adapters/calil.test.ts +0 -69
  113. package/tests/unit/adapters/openbd.test.ts +0 -185
  114. package/tests/unit/adapters/publishers/book-tech.test.ts +0 -186
  115. package/tests/unit/adapters/publishers/born-digital.test.ts +0 -194
  116. package/tests/unit/adapters/publishers/coronasha.test.ts +0 -207
  117. package/tests/unit/adapters/publishers/gihyo.test.ts +0 -137
  118. package/tests/unit/adapters/publishers/impress.test.ts +0 -129
  119. package/tests/unit/adapters/publishers/lambdanote.test.ts +0 -85
  120. package/tests/unit/adapters/publishers/manatee.test.ts +0 -165
  121. package/tests/unit/adapters/publishers/maruzen-publishing.test.ts +0 -179
  122. package/tests/unit/adapters/publishers/optronics.test.ts +0 -208
  123. package/tests/unit/adapters/publishers/oreilly-japan.test.ts +0 -194
  124. package/tests/unit/adapters/publishers/peaks.test.ts +0 -177
  125. package/tests/unit/adapters/publishers/personal-media.test.ts +0 -199
  126. package/tests/unit/adapters/publishers/rutles.test.ts +0 -173
  127. package/tests/unit/adapters/publishers/saiensu.test.ts +0 -169
  128. package/tests/unit/adapters/publishers/seshop.test.ts +0 -174
  129. package/tests/unit/adapters/publishers/tatsu-zine.test.ts +0 -172
  130. package/tests/unit/adapters/publishers/techbookfest.test.ts +0 -94
  131. package/tests/unit/adapters/registry.test.ts +0 -37
  132. package/tests/unit/application/get-book-by-isbn.test.ts +0 -176
  133. package/tests/unit/application/get-book-detail.test.ts +0 -102
  134. package/tests/unit/application/search-books.test.ts +0 -137
  135. package/tsconfig.json +0 -17
@@ -1,137 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { readFile } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { gihyoAdapter } from "../../../../src/adapters/publishers/gihyo.js";
6
- import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
7
- import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
8
- import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
9
- import type { HtmlParser } from "../../../../src/ports/html-parser.js";
10
-
11
- // search() は JSON API のみ使用するためパーサー不要
12
- const noopParser: HtmlParser = {
13
- parse(_html) {
14
- throw new Error("gihyo adapter must not call HtmlParser during search()");
15
- },
16
- };
17
-
18
- const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
19
-
20
- describe("gihyoAdapter", () => {
21
- async function makeSearchDeps(fixtureName: string) {
22
- const body = await readFile(join(FIXTURES_DIR, fixtureName), "utf-8");
23
- const http = new MockHttpClient().addResponse(
24
- "https://gihyo.jp/api_gh/site/search",
25
- { status: 200, body },
26
- );
27
- return { http, parser: noopParser, cache: new NullCacheStore() };
28
- }
29
-
30
- async function makeDetailDeps() {
31
- const [apiBody, htmlBody] = await Promise.all([
32
- readFile(join(FIXTURES_DIR, "gihyo-search.json"), "utf-8"),
33
- readFile(join(FIXTURES_DIR, "gihyo-detail.html"), "utf-8"),
34
- ]);
35
- const http = new MockHttpClient()
36
- .addResponse("https://gihyo.jp/api_gh/site/search", { status: 200, body: apiBody })
37
- .addResponse("https://gihyo.jp/book/", { status: 200, body: htmlBody });
38
- return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
39
- }
40
-
41
- it("search() が JSON API レスポンスから BookRecord[] を返す", async () => {
42
- const deps = await makeSearchDeps("gihyo-search.json");
43
-
44
- const results = await gihyoAdapter.search({ title: "TypeScript", limit: 10 }, deps);
45
-
46
- assert.strictEqual(results.length, 2);
47
- assert.partialDeepStrictEqual(results[0], {
48
- title: "プロを目指す人のためのTypeScript入門 安全なコードの書き方から高度な型の使い方まで",
49
- authors: ["uhyo"],
50
- publisher: "技術評論社",
51
- isbn: "9784297128152",
52
- price: 3740,
53
- publishedAt: "2022-04-01",
54
- });
55
- assert.strictEqual(results[0].url, "https://gihyo.jp/book/2022/978-4-297-12815-2");
56
- assert.strictEqual(
57
- results[0].coverImageUrl,
58
- "https://gihyo.jp/assets/images/cover/2022/9784297128152.jpg",
59
- );
60
- });
61
-
62
- it("サブタイトルなし書籍はタイトルのみになる", async () => {
63
- const deps = await makeSearchDeps("gihyo-search.json");
64
- const results = await gihyoAdapter.search({ title: "TypeScript" }, deps);
65
-
66
- const book = results.find(b => b.isbn === "9784297136010");
67
- assert.strictEqual(book?.title, "TypeScriptとReact/Next.jsでつくる実践Webアプリケーション開発");
68
- });
69
-
70
- it("複数著者が配列になる", async () => {
71
- const deps = await makeSearchDeps("gihyo-search.json");
72
- const results = await gihyoAdapter.search({ title: "TypeScript" }, deps);
73
-
74
- const book = results.find(b => b.isbn === "9784297136010");
75
- assert.deepStrictEqual(book?.authors, ["手島拓也", "吉田健人", "高林佳稀"]);
76
- });
77
-
78
- it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
79
- const http = new MockHttpClient();
80
- const deps = { http, parser: noopParser, cache: new NullCacheStore() };
81
-
82
- const results = await gihyoAdapter.search({}, deps);
83
-
84
- assert.deepStrictEqual(results, []);
85
- assert.strictEqual(http.calls.length, 0);
86
- });
87
-
88
- it("search() のリクエストURLにクエリが含まれる", async () => {
89
- const deps = await makeSearchDeps("gihyo-search.json");
90
- await gihyoAdapter.search({ title: "TypeScript" }, deps);
91
-
92
- assert.ok(deps.http.calls[0].includes("search=TypeScript"));
93
- });
94
-
95
- it("author クエリが API に渡される", async () => {
96
- const deps = await makeSearchDeps("gihyo-search.json");
97
- await gihyoAdapter.search({ author: "uhyo" }, deps);
98
-
99
- assert.ok(deps.http.calls[0].includes("search=uhyo"));
100
- });
101
-
102
- describe("getDetail()", () => {
103
- it("ebookStores にソーシャルDRMとDRM付きが含まれる", async () => {
104
- const deps = await makeDetailDeps();
105
- const book = await gihyoAdapter.getDetail(
106
- "https://gihyo.jp/book/2022/978-4-297-12815-2",
107
- deps,
108
- );
109
-
110
- assert.ok(book.ebookStores !== undefined);
111
- const socialStores = book.ebookStores!.filter(s => s.drm === "social");
112
- const drmStores = book.ebookStores!.filter(s => s.drm === "drm");
113
-
114
- // Gihyo Digital Publishing は見えない購入者情報を埋め込むソーシャルDRM
115
- assert.strictEqual(socialStores.length, 1);
116
- assert.partialDeepStrictEqual(socialStores[0], {
117
- name: "Gihyo Digital Publishing",
118
- drm: "social",
119
- });
120
- assert.ok(socialStores[0].url.includes("gihyo.jp/dp/ebook/"));
121
-
122
- for (const name of ["Kindle", "楽天Kobo", "BookLive", "honto"]) {
123
- assert.ok(drmStores.some(s => s.name === name), `Expected DRM store: ${name}`);
124
- }
125
- });
126
-
127
- it("ASIN が Amazon リンクから抽出される", async () => {
128
- const deps = await makeDetailDeps();
129
- const book = await gihyoAdapter.getDetail(
130
- "https://gihyo.jp/book/2022/978-4-297-12815-2",
131
- deps,
132
- );
133
-
134
- assert.strictEqual(book.asin, "B09YGZ18ZK");
135
- });
136
- });
137
- });
@@ -1,129 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { readFile } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { impressBooksAdapter } from "../../../../src/adapters/publishers/impress.js";
6
- import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
7
- import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
8
- import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
9
-
10
- const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
11
- const DETAIL_SOCIAL_URL = "https://book.impress.co.jp/books/1125101113";
12
- const DETAIL_EPUB_URL = "https://book.impress.co.jp/books/1124101031";
13
-
14
- function makeDeps(http: MockHttpClient) {
15
- return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
16
- }
17
-
18
- async function loadFixture(name: string): Promise<string> {
19
- return readFile(join(FIXTURES_DIR, name), "utf-8");
20
- }
21
-
22
- describe("impressBooksAdapter", () => {
23
- describe("search()", () => {
24
- it("検索APIがないため常に [] を返しHTTPを呼ばない", async () => {
25
- const http = new MockHttpClient();
26
- const results = await impressBooksAdapter.search({ title: "Python" }, makeDeps(http));
27
- assert.deepStrictEqual(results, []);
28
- assert.strictEqual(http.calls.length, 0);
29
- });
30
-
31
- it("クエリが空でも [] を返しHTTPを呼ばない", async () => {
32
- const http = new MockHttpClient();
33
- const results = await impressBooksAdapter.search({}, makeDeps(http));
34
- assert.deepStrictEqual(results, []);
35
- assert.strictEqual(http.calls.length, 0);
36
- });
37
- });
38
-
39
- describe("getDetail() - ソーシャルDRM書籍", () => {
40
- it("タイトルを返す", async () => {
41
- const body = await loadFixture("impress-detail-social.html");
42
- const http = new MockHttpClient().addResponse(DETAIL_SOCIAL_URL, { status: 200, body });
43
-
44
- const book = await impressBooksAdapter.getDetail(DETAIL_SOCIAL_URL, makeDeps(http));
45
-
46
- assert.strictEqual(
47
- book.title,
48
- "いちばんやさしい 先生が校務に使えるGoogle NotebookLMの教本 人気講師が教える学校業務を効率化するAI活用法",
49
- );
50
- });
51
-
52
- it("著者名から役割語を除いて返す", async () => {
53
- const body = await loadFixture("impress-detail-social.html");
54
- const http = new MockHttpClient().addResponse(DETAIL_SOCIAL_URL, { status: 200, body });
55
-
56
- const book = await impressBooksAdapter.getDetail(DETAIL_SOCIAL_URL, makeDeps(http));
57
-
58
- assert.deepStrictEqual(book.authors, ["山本康太"]);
59
- });
60
-
61
- it("ISBN・発売日・価格を返す", async () => {
62
- const body = await loadFixture("impress-detail-social.html");
63
- const http = new MockHttpClient().addResponse(DETAIL_SOCIAL_URL, { status: 200, body });
64
-
65
- const book = await impressBooksAdapter.getDetail(DETAIL_SOCIAL_URL, makeDeps(http));
66
-
67
- assert.partialDeepStrictEqual(book, {
68
- isbn: "9784295023654",
69
- publishedAt: "2026-01-22",
70
- price: 1980,
71
- });
72
- });
73
-
74
- it("publisher が インプレスブックス になる", async () => {
75
- const body = await loadFixture("impress-detail-social.html");
76
- const http = new MockHttpClient().addResponse(DETAIL_SOCIAL_URL, { status: 200, body });
77
-
78
- const book = await impressBooksAdapter.getDetail(DETAIL_SOCIAL_URL, makeDeps(http));
79
-
80
- assert.strictEqual(book.publisher, "インプレスブックス");
81
- });
82
-
83
- it("ebookStores に インプレスブックス (social) が含まれる", async () => {
84
- const body = await loadFixture("impress-detail-social.html");
85
- const http = new MockHttpClient().addResponse(DETAIL_SOCIAL_URL, { status: 200, body });
86
-
87
- const book = await impressBooksAdapter.getDetail(DETAIL_SOCIAL_URL, makeDeps(http));
88
-
89
- assert.deepStrictEqual(book.ebookStores, [
90
- { name: "インプレスブックス", url: DETAIL_SOCIAL_URL, drm: "social" },
91
- ]);
92
- });
93
-
94
- it("coverImageUrl が https: から始まる絶対URL になる", async () => {
95
- const body = await loadFixture("impress-detail-social.html");
96
- const http = new MockHttpClient().addResponse(DETAIL_SOCIAL_URL, { status: 200, body });
97
-
98
- const book = await impressBooksAdapter.getDetail(DETAIL_SOCIAL_URL, makeDeps(http));
99
-
100
- assert.strictEqual(
101
- book.coverImageUrl,
102
- "https://img.ips.co.jp/ij/25/1125101113/1125101113-520x.jpg",
103
- );
104
- });
105
- });
106
-
107
- describe("getDetail() - EPUB書籍", () => {
108
- it("著者名から役割語を除いて返す", async () => {
109
- const body = await loadFixture("impress-detail-epub.html");
110
- const http = new MockHttpClient().addResponse(DETAIL_EPUB_URL, { status: 200, body });
111
-
112
- const book = await impressBooksAdapter.getDetail(DETAIL_EPUB_URL, makeDeps(http));
113
-
114
- assert.deepStrictEqual(book.authors, ["廣瀬 豪"]);
115
- });
116
-
117
- it("DRM情報が明示されない EPUB 書籍は social として返す", async () => {
118
- const body = await loadFixture("impress-detail-epub.html");
119
- const http = new MockHttpClient().addResponse(DETAIL_EPUB_URL, { status: 200, body });
120
-
121
- const book = await impressBooksAdapter.getDetail(DETAIL_EPUB_URL, makeDeps(http));
122
-
123
- assert.partialDeepStrictEqual(book.ebookStores[0], {
124
- name: "インプレスブックス",
125
- drm: "social",
126
- });
127
- });
128
- });
129
- });
@@ -1,85 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { readFile } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { lambdanoteAdapter } from "../../../../src/adapters/publishers/lambdanote.js";
6
- import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
7
- import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
8
- import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
9
-
10
- const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
11
-
12
- function makeDeps(http: MockHttpClient) {
13
- return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
14
- }
15
-
16
- describe("lambdanoteAdapter", () => {
17
- it("search() が HTML 検索結果から BookRecord[] を返す", async () => {
18
- const body = await readFile(join(FIXTURES_DIR, "lambdanote-search.html"), "utf-8");
19
- const http = new MockHttpClient().addResponse(
20
- "https://www.lambdanote.com/search",
21
- { status: 200, body },
22
- );
23
-
24
- const results = await lambdanoteAdapter.search({ title: "Go" }, makeDeps(http));
25
-
26
- assert.strictEqual(results.length, 2);
27
- assert.partialDeepStrictEqual(results[0], {
28
- title: "Goならわかるシステムプログラミング 第2版",
29
- publisher: "ラムダノート",
30
- price: 3960,
31
- });
32
- assert.strictEqual(results[0].url, "https://www.lambdanote.com/products/go-2");
33
- assert.ok(results[0].coverImageUrl?.includes("go2_small.jpg"));
34
- });
35
-
36
- it("2件目の書籍も正しく取得できる", async () => {
37
- const body = await readFile(join(FIXTURES_DIR, "lambdanote-search.html"), "utf-8");
38
- const http = new MockHttpClient().addResponse(
39
- "https://www.lambdanote.com/search",
40
- { status: 200, body },
41
- );
42
-
43
- const results = await lambdanoteAdapter.search({ title: "Go" }, makeDeps(http));
44
-
45
- assert.partialDeepStrictEqual(results[1], {
46
- title: "プログラミング言語Go",
47
- price: 4400,
48
- });
49
- assert.strictEqual(results[1].url, "https://www.lambdanote.com/products/gopl");
50
- });
51
-
52
- it("limit を適用する", async () => {
53
- const body = await readFile(join(FIXTURES_DIR, "lambdanote-search.html"), "utf-8");
54
- const http = new MockHttpClient().addResponse(
55
- "https://www.lambdanote.com/search",
56
- { status: 200, body },
57
- );
58
-
59
- const results = await lambdanoteAdapter.search({ title: "Go", limit: 1 }, makeDeps(http));
60
-
61
- assert.strictEqual(results.length, 1);
62
- });
63
-
64
- it("結果ゼロの場合は [] を返す", async () => {
65
- const body = `<!DOCTYPE html><html><body>
66
- <ul class="search-results__list"></ul>
67
- </body></html>`;
68
- const http = new MockHttpClient().addResponse(
69
- "https://www.lambdanote.com/search",
70
- { status: 200, body },
71
- );
72
-
73
- const results = await lambdanoteAdapter.search({ title: "存在しない本" }, makeDeps(http));
74
-
75
- assert.deepStrictEqual(results, []);
76
- });
77
-
78
- it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
79
- const http = new MockHttpClient();
80
- const results = await lambdanoteAdapter.search({}, makeDeps(http));
81
-
82
- assert.deepStrictEqual(results, []);
83
- assert.strictEqual(http.calls.length, 0);
84
- });
85
- });
@@ -1,165 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { readFile } from "node:fs/promises";
4
- import { join } from "node:path";
5
- import { manateeAdapter } from "../../../../src/adapters/publishers/manatee.js";
6
- import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
7
- import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
8
- import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
9
-
10
- const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
11
-
12
- function makeDeps(http: MockHttpClient) {
13
- return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
14
- }
15
-
16
- async function loadFixture(name: string): Promise<string> {
17
- return readFile(join(FIXTURES_DIR, name), "utf-8");
18
- }
19
-
20
- describe("manateeAdapter", () => {
21
- describe("search()", () => {
22
- it("検索結果から BookRecord[] を返す", async () => {
23
- const body = await loadFixture("manatee-search.html");
24
- const http = new MockHttpClient().addResponse(
25
- "https://book.mynavi.jp/manatee/books/",
26
- { status: 200, body },
27
- );
28
-
29
- const results = await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
30
-
31
- assert.strictEqual(results.length, 3);
32
- assert.partialDeepStrictEqual(results[0], {
33
- title: "現場で使えるTypeScript 詳解実践ガイド",
34
- publisher: "マナティ",
35
- url: "https://book.mynavi.jp/manatee/books/detail/id=142711",
36
- price: 2948,
37
- });
38
- });
39
-
40
- it("ebookStores にマナティ(ソーシャルDRM)が含まれる", async () => {
41
- const body = await loadFixture("manatee-search.html");
42
- const http = new MockHttpClient().addResponse(
43
- "https://book.mynavi.jp/manatee/books/",
44
- { status: 200, body },
45
- );
46
-
47
- const results = await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
48
-
49
- assert.deepStrictEqual(results[0].ebookStores, [
50
- {
51
- name: "マナティ",
52
- url: "https://book.mynavi.jp/manatee/books/detail/id=142711",
53
- drm: "social",
54
- },
55
- ]);
56
- });
57
-
58
- it("coverImageUrl が設定される", async () => {
59
- const body = await loadFixture("manatee-search.html");
60
- const http = new MockHttpClient().addResponse(
61
- "https://book.mynavi.jp/manatee/books/",
62
- { status: 200, body },
63
- );
64
-
65
- const results = await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
66
-
67
- assert.strictEqual(
68
- results[0].coverImageUrl,
69
- "https://book.mynavi.jp/files/topics/142711_ext_06_0.jpg",
70
- );
71
- });
72
-
73
- it("limit を適用する", async () => {
74
- const body = await loadFixture("manatee-search.html");
75
- const http = new MockHttpClient().addResponse(
76
- "https://book.mynavi.jp/manatee/books/",
77
- { status: 200, body },
78
- );
79
-
80
- const results = await manateeAdapter.search({ title: "TypeScript", limit: 2 }, makeDeps(http));
81
-
82
- assert.strictEqual(results.length, 2);
83
- });
84
-
85
- it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
86
- const http = new MockHttpClient();
87
-
88
- const results = await manateeAdapter.search({}, makeDeps(http));
89
-
90
- assert.deepStrictEqual(results, []);
91
- assert.strictEqual(http.calls.length, 0);
92
- });
93
-
94
- it("検索リクエストに topics_keyword が含まれる", async () => {
95
- const body = await loadFixture("manatee-search.html");
96
- const http = new MockHttpClient().addResponse(
97
- "https://book.mynavi.jp/manatee/books/",
98
- { status: 200, body },
99
- );
100
-
101
- await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
102
-
103
- assert.ok(http.calls[0].includes("topics_keyword=TypeScript"));
104
- });
105
- });
106
-
107
- describe("getDetail()", () => {
108
- it("詳細情報を返す", async () => {
109
- const body = await loadFixture("manatee-detail.html");
110
- const http = new MockHttpClient().addResponse(
111
- "https://book.mynavi.jp/manatee/books/detail/id=142711",
112
- { status: 200, body },
113
- );
114
-
115
- const book = await manateeAdapter.getDetail(
116
- "https://book.mynavi.jp/manatee/books/detail/id=142711",
117
- makeDeps(http),
118
- );
119
-
120
- assert.partialDeepStrictEqual(book, {
121
- title: "現場で使えるTypeScript 詳解実践ガイド",
122
- publisher: "マイナビ出版",
123
- isbn: "9784839984274",
124
- price: 2948,
125
- publishedAt: "2024-03-22",
126
- });
127
- });
128
-
129
- it("著者が配列で返される", async () => {
130
- const body = await loadFixture("manatee-detail.html");
131
- const http = new MockHttpClient().addResponse(
132
- "https://book.mynavi.jp/manatee/books/detail/id=142711",
133
- { status: 200, body },
134
- );
135
-
136
- const book = await manateeAdapter.getDetail(
137
- "https://book.mynavi.jp/manatee/books/detail/id=142711",
138
- makeDeps(http),
139
- );
140
-
141
- assert.deepStrictEqual(book.authors, ["菅原浩之", "CodeMafia", "外村将大"]);
142
- });
143
-
144
- it("ebookStores にマナティ(ソーシャルDRM)が含まれる", async () => {
145
- const body = await loadFixture("manatee-detail.html");
146
- const http = new MockHttpClient().addResponse(
147
- "https://book.mynavi.jp/manatee/books/detail/id=142711",
148
- { status: 200, body },
149
- );
150
-
151
- const book = await manateeAdapter.getDetail(
152
- "https://book.mynavi.jp/manatee/books/detail/id=142711",
153
- makeDeps(http),
154
- );
155
-
156
- assert.deepStrictEqual(book.ebookStores, [
157
- {
158
- name: "マナティ",
159
- url: "https://book.mynavi.jp/manatee/books/detail/id=142711",
160
- drm: "social",
161
- },
162
- ]);
163
- });
164
- });
165
- });