@zonuexe/techbook-mcp 0.2.3 → 0.3.1

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 (207) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/README.md +54 -22
  3. package/dist/adapters/http/fetch-client.d.ts.map +1 -1
  4. package/dist/adapters/http/fetch-client.js +18 -1
  5. package/dist/adapters/http/fetch-client.js.map +1 -1
  6. package/dist/adapters/openbd.d.ts.map +1 -1
  7. package/dist/adapters/openbd.js +18 -5
  8. package/dist/adapters/openbd.js.map +1 -1
  9. package/dist/adapters/publishers/base.d.ts +2 -1
  10. package/dist/adapters/publishers/base.d.ts.map +1 -1
  11. package/dist/adapters/publishers/base.js +8 -3
  12. package/dist/adapters/publishers/base.js.map +1 -1
  13. package/dist/adapters/publishers/cq-publishing.d.ts +3 -0
  14. package/dist/adapters/publishers/cq-publishing.d.ts.map +1 -0
  15. package/dist/adapters/publishers/cq-publishing.js +120 -0
  16. package/dist/adapters/publishers/cq-publishing.js.map +1 -0
  17. package/dist/adapters/publishers/google-books.d.ts +4 -0
  18. package/dist/adapters/publishers/google-books.d.ts.map +1 -0
  19. package/dist/adapters/publishers/google-books.js +76 -0
  20. package/dist/adapters/publishers/google-books.js.map +1 -0
  21. package/dist/adapters/publishers/isbn-publisher-codes.d.ts +21 -0
  22. package/dist/adapters/publishers/isbn-publisher-codes.d.ts.map +1 -0
  23. package/dist/adapters/publishers/isbn-publisher-codes.js +49 -0
  24. package/dist/adapters/publishers/isbn-publisher-codes.js.map +1 -0
  25. package/dist/adapters/publishers/juse-p.d.ts +3 -0
  26. package/dist/adapters/publishers/juse-p.d.ts.map +1 -0
  27. package/dist/adapters/publishers/juse-p.js +110 -0
  28. package/dist/adapters/publishers/juse-p.js.map +1 -0
  29. package/dist/adapters/publishers/leanpub.d.ts +3 -0
  30. package/dist/adapters/publishers/leanpub.d.ts.map +1 -0
  31. package/dist/adapters/publishers/leanpub.js +96 -0
  32. package/dist/adapters/publishers/leanpub.js.map +1 -0
  33. package/dist/adapters/publishers/oreilly-japan.d.ts.map +1 -1
  34. package/dist/adapters/publishers/oreilly-japan.js +8 -2
  35. package/dist/adapters/publishers/oreilly-japan.js.map +1 -1
  36. package/dist/adapters/publishers/peaks.d.ts.map +1 -1
  37. package/dist/adapters/publishers/peaks.js +3 -2
  38. package/dist/adapters/publishers/peaks.js.map +1 -1
  39. package/dist/adapters/publishers/personal-media.d.ts.map +1 -1
  40. package/dist/adapters/publishers/personal-media.js +3 -2
  41. package/dist/adapters/publishers/personal-media.js.map +1 -1
  42. package/dist/adapters/publishers/pragprog.d.ts +3 -0
  43. package/dist/adapters/publishers/pragprog.d.ts.map +1 -0
  44. package/dist/adapters/publishers/pragprog.js +120 -0
  45. package/dist/adapters/publishers/pragprog.js.map +1 -0
  46. package/dist/adapters/publishers/registry.d.ts.map +1 -1
  47. package/dist/adapters/publishers/registry.js +10 -0
  48. package/dist/adapters/publishers/registry.js.map +1 -1
  49. package/dist/adapters/publishers/techbookfest.d.ts.map +1 -1
  50. package/dist/adapters/publishers/techbookfest.js +2 -1
  51. package/dist/adapters/publishers/techbookfest.js.map +1 -1
  52. package/dist/application/concurrency.d.ts +16 -0
  53. package/dist/application/concurrency.d.ts.map +1 -0
  54. package/dist/application/concurrency.js +42 -0
  55. package/dist/application/concurrency.js.map +1 -0
  56. package/dist/application/get-book-by-isbn.d.ts +0 -8
  57. package/dist/application/get-book-by-isbn.d.ts.map +1 -1
  58. package/dist/application/get-book-by-isbn.js +64 -7
  59. package/dist/application/get-book-by-isbn.js.map +1 -1
  60. package/dist/application/get-book-detail.d.ts.map +1 -1
  61. package/dist/application/get-book-detail.js +3 -0
  62. package/dist/application/get-book-detail.js.map +1 -1
  63. package/dist/application/search-books.d.ts +16 -5
  64. package/dist/application/search-books.d.ts.map +1 -1
  65. package/dist/application/search-books.js +46 -9
  66. package/dist/application/search-books.js.map +1 -1
  67. package/dist/config/credentials.d.ts +8 -0
  68. package/dist/config/credentials.d.ts.map +1 -0
  69. package/dist/config/credentials.js +32 -0
  70. package/dist/config/credentials.js.map +1 -0
  71. package/dist/domain/authors.d.ts +7 -0
  72. package/dist/domain/authors.d.ts.map +1 -0
  73. package/dist/domain/authors.js +22 -0
  74. package/dist/domain/authors.js.map +1 -0
  75. package/dist/domain/book.d.ts +2 -0
  76. package/dist/domain/book.d.ts.map +1 -1
  77. package/dist/domain/isbn.d.ts +8 -0
  78. package/dist/domain/isbn.d.ts.map +1 -0
  79. package/dist/domain/isbn.js +16 -0
  80. package/dist/domain/isbn.js.map +1 -0
  81. package/dist/domain/publisher.d.ts +16 -0
  82. package/dist/domain/publisher.d.ts.map +1 -1
  83. package/dist/domain/text-match.d.ts +32 -0
  84. package/dist/domain/text-match.d.ts.map +1 -0
  85. package/dist/domain/text-match.js +84 -0
  86. package/dist/domain/text-match.js.map +1 -0
  87. package/dist/main.js +15 -1
  88. package/dist/main.js.map +1 -1
  89. package/dist/mcp/server.d.ts +6 -0
  90. package/dist/mcp/server.d.ts.map +1 -1
  91. package/dist/mcp/server.js +40 -4
  92. package/dist/mcp/server.js.map +1 -1
  93. package/dist/mcp/tools.d.ts.map +1 -1
  94. package/dist/mcp/tools.js +9 -1
  95. package/dist/mcp/tools.js.map +1 -1
  96. package/dist/setup.d.ts +2 -0
  97. package/dist/setup.d.ts.map +1 -0
  98. package/dist/setup.js +43 -0
  99. package/dist/setup.js.map +1 -0
  100. package/dist/version.d.ts +9 -0
  101. package/dist/version.d.ts.map +1 -0
  102. package/dist/version.js +9 -0
  103. package/dist/version.js.map +1 -0
  104. package/docs/design-doc.md +127 -7
  105. package/package.json +14 -15
  106. package/.claude/settings.local.json +0 -38
  107. package/.codex/skills/techbook-mcp-release-prep/SKILL.md +0 -105
  108. package/.github/workflows/test.yml +0 -72
  109. package/.oxlintrc.json +0 -12
  110. package/AGENTS.md +0 -100
  111. package/deno.json +0 -3
  112. package/src/adapters/cache/memory-cache.ts +0 -31
  113. package/src/adapters/cache/null-cache.ts +0 -8
  114. package/src/adapters/calil.ts +0 -57
  115. package/src/adapters/html/cheerio-parser.ts +0 -50
  116. package/src/adapters/http/fetch-client.ts +0 -47
  117. package/src/adapters/http/mock-client.ts +0 -77
  118. package/src/adapters/openbd.ts +0 -142
  119. package/src/adapters/publishers/base.ts +0 -279
  120. package/src/adapters/publishers/book-tech.ts +0 -117
  121. package/src/adapters/publishers/born-digital.ts +0 -143
  122. package/src/adapters/publishers/coronasha.ts +0 -139
  123. package/src/adapters/publishers/gihyo.ts +0 -120
  124. package/src/adapters/publishers/impress.ts +0 -103
  125. package/src/adapters/publishers/lambdanote.ts +0 -146
  126. package/src/adapters/publishers/manatee.ts +0 -113
  127. package/src/adapters/publishers/maruzen-publishing.ts +0 -129
  128. package/src/adapters/publishers/optronics.ts +0 -113
  129. package/src/adapters/publishers/oreilly-japan.ts +0 -133
  130. package/src/adapters/publishers/peaks.ts +0 -98
  131. package/src/adapters/publishers/personal-media.ts +0 -168
  132. package/src/adapters/publishers/registry.ts +0 -38
  133. package/src/adapters/publishers/rutles.ts +0 -149
  134. package/src/adapters/publishers/saiensu.ts +0 -136
  135. package/src/adapters/publishers/seshop.ts +0 -121
  136. package/src/adapters/publishers/tatsu-zine.ts +0 -142
  137. package/src/adapters/publishers/techbookfest.ts +0 -179
  138. package/src/application/get-book-by-isbn.ts +0 -50
  139. package/src/application/get-book-detail.ts +0 -40
  140. package/src/application/search-books.ts +0 -64
  141. package/src/domain/book.ts +0 -35
  142. package/src/domain/publisher.ts +0 -18
  143. package/src/main.ts +0 -14
  144. package/src/mcp/server.ts +0 -113
  145. package/src/mcp/tools.ts +0 -71
  146. package/src/ports/cache.ts +0 -5
  147. package/src/ports/html-parser.ts +0 -15
  148. package/src/ports/http.ts +0 -17
  149. package/tests/fixtures/book-tech-detail.html +0 -51
  150. package/tests/fixtures/book-tech-search.html +0 -91
  151. package/tests/fixtures/born-digital-detail.html +0 -62
  152. package/tests/fixtures/born-digital-search.html +0 -51
  153. package/tests/fixtures/calil-book.html +0 -987
  154. package/tests/fixtures/coronasha-detail.html +0 -41
  155. package/tests/fixtures/coronasha-search.html +0 -61
  156. package/tests/fixtures/gihyo-detail.html +0 -42
  157. package/tests/fixtures/gihyo-search.json +0 -54
  158. package/tests/fixtures/impress-detail-epub.html +0 -746
  159. package/tests/fixtures/impress-detail-social.html +0 -689
  160. package/tests/fixtures/lambdanote-search.html +0 -66
  161. package/tests/fixtures/manatee-detail.html +0 -53
  162. package/tests/fixtures/manatee-search.html +0 -59
  163. package/tests/fixtures/maruzen-detail.html +0 -51
  164. package/tests/fixtures/maruzen-search.html +0 -60
  165. package/tests/fixtures/openbd-response.json +0 -110
  166. package/tests/fixtures/optronics-detail.html +0 -30
  167. package/tests/fixtures/optronics-search.html +0 -75
  168. package/tests/fixtures/oreilly-detail.html +0 -52
  169. package/tests/fixtures/oreilly-ebook-list.html +0 -53
  170. package/tests/fixtures/peaks-detail.html +0 -39
  171. package/tests/fixtures/peaks-top.html +0 -50
  172. package/tests/fixtures/personal-media-detail.html +0 -32
  173. package/tests/fixtures/personal-media-search.html +0 -39
  174. package/tests/fixtures/rutles-detail.html +0 -32
  175. package/tests/fixtures/rutles-search.html +0 -62
  176. package/tests/fixtures/saiensu-detail.html +0 -41
  177. package/tests/fixtures/saiensu-search.html +0 -65
  178. package/tests/fixtures/seshop-detail.html +0 -45
  179. package/tests/fixtures/seshop-search.html +0 -58
  180. package/tests/fixtures/tatsu-zine-detail-free.html +0 -24
  181. package/tests/fixtures/tatsu-zine-search.html +0 -40
  182. package/tests/fixtures/techbookfest-search.json +0 -73
  183. package/tests/unit/adapters/base.test.ts +0 -441
  184. package/tests/unit/adapters/calil.test.ts +0 -69
  185. package/tests/unit/adapters/openbd.test.ts +0 -185
  186. package/tests/unit/adapters/publishers/book-tech.test.ts +0 -186
  187. package/tests/unit/adapters/publishers/born-digital.test.ts +0 -194
  188. package/tests/unit/adapters/publishers/coronasha.test.ts +0 -207
  189. package/tests/unit/adapters/publishers/gihyo.test.ts +0 -137
  190. package/tests/unit/adapters/publishers/impress.test.ts +0 -129
  191. package/tests/unit/adapters/publishers/lambdanote.test.ts +0 -85
  192. package/tests/unit/adapters/publishers/manatee.test.ts +0 -165
  193. package/tests/unit/adapters/publishers/maruzen-publishing.test.ts +0 -179
  194. package/tests/unit/adapters/publishers/optronics.test.ts +0 -208
  195. package/tests/unit/adapters/publishers/oreilly-japan.test.ts +0 -194
  196. package/tests/unit/adapters/publishers/peaks.test.ts +0 -177
  197. package/tests/unit/adapters/publishers/personal-media.test.ts +0 -199
  198. package/tests/unit/adapters/publishers/rutles.test.ts +0 -173
  199. package/tests/unit/adapters/publishers/saiensu.test.ts +0 -169
  200. package/tests/unit/adapters/publishers/seshop.test.ts +0 -174
  201. package/tests/unit/adapters/publishers/tatsu-zine.test.ts +0 -172
  202. package/tests/unit/adapters/publishers/techbookfest.test.ts +0 -94
  203. package/tests/unit/adapters/registry.test.ts +0 -37
  204. package/tests/unit/application/get-book-by-isbn.test.ts +0 -176
  205. package/tests/unit/application/get-book-detail.test.ts +0 -102
  206. package/tests/unit/application/search-books.test.ts +0 -137
  207. 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
- });