@zonuexe/techbook-mcp 0.2.2 → 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 (151) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/README.md +39 -20
  3. package/dist/adapters/calil.d.ts +10 -0
  4. package/dist/adapters/calil.d.ts.map +1 -0
  5. package/dist/adapters/calil.js +45 -0
  6. package/dist/adapters/calil.js.map +1 -0
  7. package/dist/adapters/openbd.d.ts +57 -0
  8. package/dist/adapters/openbd.d.ts.map +1 -0
  9. package/dist/adapters/openbd.js +87 -0
  10. package/dist/adapters/openbd.js.map +1 -0
  11. package/dist/adapters/publishers/google-books.d.ts +4 -0
  12. package/dist/adapters/publishers/google-books.d.ts.map +1 -0
  13. package/dist/adapters/publishers/google-books.js +75 -0
  14. package/dist/adapters/publishers/google-books.js.map +1 -0
  15. package/dist/adapters/publishers/isbn-publisher-codes.d.ts +21 -0
  16. package/dist/adapters/publishers/isbn-publisher-codes.d.ts.map +1 -0
  17. package/dist/adapters/publishers/isbn-publisher-codes.js +49 -0
  18. package/dist/adapters/publishers/isbn-publisher-codes.js.map +1 -0
  19. package/dist/adapters/publishers/juse-p.d.ts +3 -0
  20. package/dist/adapters/publishers/juse-p.d.ts.map +1 -0
  21. package/dist/adapters/publishers/juse-p.js +110 -0
  22. package/dist/adapters/publishers/juse-p.js.map +1 -0
  23. package/dist/adapters/publishers/registry.d.ts.map +1 -1
  24. package/dist/adapters/publishers/registry.js +4 -0
  25. package/dist/adapters/publishers/registry.js.map +1 -1
  26. package/dist/adapters/publishers/tatsu-zine.d.ts.map +1 -1
  27. package/dist/adapters/publishers/tatsu-zine.js +6 -18
  28. package/dist/adapters/publishers/tatsu-zine.js.map +1 -1
  29. package/dist/application/get-book-by-isbn.d.ts +13 -0
  30. package/dist/application/get-book-by-isbn.d.ts.map +1 -0
  31. package/dist/application/get-book-by-isbn.js +61 -0
  32. package/dist/application/get-book-by-isbn.js.map +1 -0
  33. package/dist/application/get-book-detail.d.ts.map +1 -1
  34. package/dist/application/get-book-detail.js +16 -1
  35. package/dist/application/get-book-detail.js.map +1 -1
  36. package/dist/application/search-books.d.ts.map +1 -1
  37. package/dist/application/search-books.js +20 -0
  38. package/dist/application/search-books.js.map +1 -1
  39. package/dist/config/credentials.d.ts +8 -0
  40. package/dist/config/credentials.d.ts.map +1 -0
  41. package/dist/config/credentials.js +32 -0
  42. package/dist/config/credentials.js.map +1 -0
  43. package/dist/main.js +15 -1
  44. package/dist/main.js.map +1 -1
  45. package/dist/mcp/server.d.ts.map +1 -1
  46. package/dist/mcp/server.js +10 -0
  47. package/dist/mcp/server.js.map +1 -1
  48. package/dist/mcp/tools.d.ts +13 -0
  49. package/dist/mcp/tools.d.ts.map +1 -1
  50. package/dist/mcp/tools.js +16 -0
  51. package/dist/mcp/tools.js.map +1 -1
  52. package/dist/setup.d.ts +2 -0
  53. package/dist/setup.d.ts.map +1 -0
  54. package/dist/setup.js +43 -0
  55. package/dist/setup.js.map +1 -0
  56. package/flake.lock +61 -0
  57. package/package.json +1 -1
  58. package/.claude/settings.local.json +0 -36
  59. package/.codex/skills/techbook-mcp-release-prep/SKILL.md +0 -105
  60. package/.github/workflows/test.yml +0 -72
  61. package/.oxlintrc.json +0 -12
  62. package/AGENTS.md +0 -100
  63. package/deno.json +0 -3
  64. package/src/adapters/cache/memory-cache.ts +0 -31
  65. package/src/adapters/cache/null-cache.ts +0 -8
  66. package/src/adapters/html/cheerio-parser.ts +0 -50
  67. package/src/adapters/http/fetch-client.ts +0 -47
  68. package/src/adapters/http/mock-client.ts +0 -77
  69. package/src/adapters/publishers/base.ts +0 -279
  70. package/src/adapters/publishers/book-tech.ts +0 -117
  71. package/src/adapters/publishers/born-digital.ts +0 -143
  72. package/src/adapters/publishers/coronasha.ts +0 -139
  73. package/src/adapters/publishers/gihyo.ts +0 -120
  74. package/src/adapters/publishers/impress.ts +0 -103
  75. package/src/adapters/publishers/lambdanote.ts +0 -146
  76. package/src/adapters/publishers/manatee.ts +0 -113
  77. package/src/adapters/publishers/maruzen-publishing.ts +0 -129
  78. package/src/adapters/publishers/optronics.ts +0 -113
  79. package/src/adapters/publishers/oreilly-japan.ts +0 -133
  80. package/src/adapters/publishers/peaks.ts +0 -98
  81. package/src/adapters/publishers/personal-media.ts +0 -168
  82. package/src/adapters/publishers/registry.ts +0 -38
  83. package/src/adapters/publishers/rutles.ts +0 -149
  84. package/src/adapters/publishers/saiensu.ts +0 -136
  85. package/src/adapters/publishers/seshop.ts +0 -121
  86. package/src/adapters/publishers/tatsu-zine.ts +0 -154
  87. package/src/adapters/publishers/techbookfest.ts +0 -179
  88. package/src/application/get-book-detail.ts +0 -24
  89. package/src/application/search-books.ts +0 -44
  90. package/src/domain/book.ts +0 -35
  91. package/src/domain/publisher.ts +0 -18
  92. package/src/main.ts +0 -14
  93. package/src/mcp/server.ts +0 -103
  94. package/src/mcp/tools.ts +0 -54
  95. package/src/ports/cache.ts +0 -5
  96. package/src/ports/html-parser.ts +0 -15
  97. package/src/ports/http.ts +0 -17
  98. package/tests/fixtures/book-tech-detail.html +0 -51
  99. package/tests/fixtures/book-tech-search.html +0 -91
  100. package/tests/fixtures/born-digital-detail.html +0 -62
  101. package/tests/fixtures/born-digital-search.html +0 -51
  102. package/tests/fixtures/coronasha-detail.html +0 -41
  103. package/tests/fixtures/coronasha-search.html +0 -61
  104. package/tests/fixtures/gihyo-detail.html +0 -42
  105. package/tests/fixtures/gihyo-search.json +0 -54
  106. package/tests/fixtures/impress-detail-epub.html +0 -746
  107. package/tests/fixtures/impress-detail-social.html +0 -689
  108. package/tests/fixtures/lambdanote-search.html +0 -66
  109. package/tests/fixtures/manatee-detail.html +0 -53
  110. package/tests/fixtures/manatee-search.html +0 -59
  111. package/tests/fixtures/maruzen-detail.html +0 -51
  112. package/tests/fixtures/maruzen-search.html +0 -60
  113. package/tests/fixtures/optronics-detail.html +0 -30
  114. package/tests/fixtures/optronics-search.html +0 -75
  115. package/tests/fixtures/oreilly-detail.html +0 -52
  116. package/tests/fixtures/oreilly-ebook-list.html +0 -53
  117. package/tests/fixtures/peaks-detail.html +0 -39
  118. package/tests/fixtures/peaks-top.html +0 -50
  119. package/tests/fixtures/personal-media-detail.html +0 -32
  120. package/tests/fixtures/personal-media-search.html +0 -39
  121. package/tests/fixtures/rutles-detail.html +0 -32
  122. package/tests/fixtures/rutles-search.html +0 -62
  123. package/tests/fixtures/saiensu-detail.html +0 -41
  124. package/tests/fixtures/saiensu-search.html +0 -65
  125. package/tests/fixtures/seshop-detail.html +0 -45
  126. package/tests/fixtures/seshop-search.html +0 -58
  127. package/tests/fixtures/tatsu-zine-detail-free.html +0 -22
  128. package/tests/fixtures/tatsu-zine-search.html +0 -40
  129. package/tests/fixtures/techbookfest-search.json +0 -73
  130. package/tests/unit/adapters/base.test.ts +0 -441
  131. package/tests/unit/adapters/publishers/book-tech.test.ts +0 -186
  132. package/tests/unit/adapters/publishers/born-digital.test.ts +0 -194
  133. package/tests/unit/adapters/publishers/coronasha.test.ts +0 -207
  134. package/tests/unit/adapters/publishers/gihyo.test.ts +0 -137
  135. package/tests/unit/adapters/publishers/impress.test.ts +0 -129
  136. package/tests/unit/adapters/publishers/lambdanote.test.ts +0 -85
  137. package/tests/unit/adapters/publishers/manatee.test.ts +0 -165
  138. package/tests/unit/adapters/publishers/maruzen-publishing.test.ts +0 -179
  139. package/tests/unit/adapters/publishers/optronics.test.ts +0 -208
  140. package/tests/unit/adapters/publishers/oreilly-japan.test.ts +0 -194
  141. package/tests/unit/adapters/publishers/peaks.test.ts +0 -177
  142. package/tests/unit/adapters/publishers/personal-media.test.ts +0 -199
  143. package/tests/unit/adapters/publishers/rutles.test.ts +0 -173
  144. package/tests/unit/adapters/publishers/saiensu.test.ts +0 -169
  145. package/tests/unit/adapters/publishers/seshop.test.ts +0 -174
  146. package/tests/unit/adapters/publishers/tatsu-zine.test.ts +0 -172
  147. package/tests/unit/adapters/publishers/techbookfest.test.ts +0 -94
  148. package/tests/unit/adapters/registry.test.ts +0 -37
  149. package/tests/unit/application/get-book-detail.test.ts +0 -102
  150. package/tests/unit/application/search-books.test.ts +0 -137
  151. package/tsconfig.json +0 -17
@@ -1,173 +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 { rutlesAdapter } from "../../../../src/adapters/publishers/rutles.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("rutlesAdapter", () => {
21
- describe("search()", () => {
22
- it("【電子版】のみ BookRecord[] を返す(紙書籍は除外)", async () => {
23
- const body = await loadFixture("rutles-search.html");
24
- const http = new MockHttpClient().addResponse(
25
- "https://shop.rutles.net/",
26
- { status: 200, body },
27
- );
28
-
29
- const results = await rutlesAdapter.search({ title: "C言語" }, makeDeps(http));
30
-
31
- // フィクスチャには電子2件・紙1件、電子のみ返す
32
- assert.strictEqual(results.length, 2);
33
- assert.partialDeepStrictEqual(results[0], {
34
- title: "【電子版】C言語3Dゲームプログラミング教室",
35
- publisher: "ラトルズ",
36
- url: "https://shop.rutles.net/?pid=173173393",
37
- price: 3168,
38
- });
39
- });
40
-
41
- it("coverImageUrl が設定される", async () => {
42
- const body = await loadFixture("rutles-search.html");
43
- const http = new MockHttpClient().addResponse(
44
- "https://shop.rutles.net/",
45
- { status: 200, body },
46
- );
47
-
48
- const results = await rutlesAdapter.search({ title: "C言語" }, makeDeps(http));
49
-
50
- assert.strictEqual(
51
- results[0].coverImageUrl,
52
- "https://img21.shop-pro.jp/PA01496/800/product/173173393_th.jpg",
53
- );
54
- });
55
-
56
- it("ebookStores にラトルズ(DRMフリー)が含まれる", async () => {
57
- const body = await loadFixture("rutles-search.html");
58
- const http = new MockHttpClient().addResponse(
59
- "https://shop.rutles.net/",
60
- { status: 200, body },
61
- );
62
-
63
- const results = await rutlesAdapter.search({ title: "C言語" }, makeDeps(http));
64
-
65
- assert.deepStrictEqual(results[0].ebookStores, [
66
- {
67
- name: "ラトルズ",
68
- url: "https://shop.rutles.net/?pid=173173393",
69
- drm: "free",
70
- },
71
- ]);
72
- });
73
-
74
- it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
75
- const http = new MockHttpClient();
76
-
77
- const results = await rutlesAdapter.search({}, makeDeps(http));
78
-
79
- assert.deepStrictEqual(results, []);
80
- assert.strictEqual(http.calls.length, 0);
81
- });
82
-
83
- it("検索URLに EUC-JP エンコードされたキーワードが含まれる", async () => {
84
- const body = await loadFixture("rutles-search.html");
85
- const http = new MockHttpClient().addResponse(
86
- "https://shop.rutles.net/",
87
- { status: 200, body },
88
- );
89
-
90
- await rutlesAdapter.search({ title: "言語" }, makeDeps(http));
91
-
92
- // "言語" の EUC-JP エンコード = %B8%C0%B8%EC
93
- assert.ok(http.calls[0].includes("%B8%C0%B8%EC"));
94
- });
95
- });
96
-
97
- describe("getDetail()", () => {
98
- it("詳細情報を返す", async () => {
99
- const body = await loadFixture("rutles-detail.html");
100
- const http = new MockHttpClient().addResponse(
101
- "https://shop.rutles.net/?pid=173173393",
102
- { status: 200, body },
103
- );
104
-
105
- const book = await rutlesAdapter.getDetail(
106
- "https://shop.rutles.net/?pid=173173393",
107
- makeDeps(http),
108
- );
109
-
110
- assert.partialDeepStrictEqual(book, {
111
- title: "【電子版】C言語3Dゲームプログラミング教室",
112
- publisher: "ラトルズ",
113
- isbn: "9784899774211",
114
- price: 3168,
115
- publishedAt: "2014-10-25",
116
- });
117
- });
118
-
119
- it("著者の役割語・所属を除去する", async () => {
120
- const body = await loadFixture("rutles-detail.html");
121
- const http = new MockHttpClient().addResponse(
122
- "https://shop.rutles.net/?pid=173173393",
123
- { status: 200, body },
124
- );
125
-
126
- const book = await rutlesAdapter.getDetail(
127
- "https://shop.rutles.net/?pid=173173393",
128
- makeDeps(http),
129
- );
130
-
131
- assert.deepStrictEqual(book.authors, ["大槻有一郎", "山田巧"]);
132
- });
133
-
134
- it("coverImageUrl が設定される", async () => {
135
- const body = await loadFixture("rutles-detail.html");
136
- const http = new MockHttpClient().addResponse(
137
- "https://shop.rutles.net/?pid=173173393",
138
- { status: 200, body },
139
- );
140
-
141
- const book = await rutlesAdapter.getDetail(
142
- "https://shop.rutles.net/?pid=173173393",
143
- makeDeps(http),
144
- );
145
-
146
- assert.strictEqual(
147
- book.coverImageUrl,
148
- "https://img21.shop-pro.jp/PA01496/800/product/173173393.jpg",
149
- );
150
- });
151
-
152
- it("ebookStores にラトルズ(DRMフリー)が含まれる", async () => {
153
- const body = await loadFixture("rutles-detail.html");
154
- const http = new MockHttpClient().addResponse(
155
- "https://shop.rutles.net/?pid=173173393",
156
- { status: 200, body },
157
- );
158
-
159
- const book = await rutlesAdapter.getDetail(
160
- "https://shop.rutles.net/?pid=173173393",
161
- makeDeps(http),
162
- );
163
-
164
- assert.deepStrictEqual(book.ebookStores, [
165
- {
166
- name: "ラトルズ",
167
- url: "https://shop.rutles.net/?pid=173173393",
168
- drm: "free",
169
- },
170
- ]);
171
- });
172
- });
173
- });
@@ -1,169 +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 { saiensuAdapter } from "../../../../src/adapters/publishers/saiensu.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("saiensuAdapter", () => {
21
- describe("search()", () => {
22
- it("電子書籍のみ BookRecord[] を返す(紙は除外)", async () => {
23
- const body = await loadFixture("saiensu-search.html");
24
- const http = new MockHttpClient().addResponse(
25
- "https://www.saiensu.co.jp/search/",
26
- { status: 200, body },
27
- );
28
-
29
- const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
30
-
31
- // フィクスチャには電子1件・紙1件あり、電子のみ返す
32
- assert.strictEqual(results.length, 1);
33
- assert.partialDeepStrictEqual(results[0], {
34
- title: "統計リテラシーI【電子版】 ―記述統計から推測統計へ",
35
- authors: ["堀井俊佑"],
36
- publisher: "サイエンス社",
37
- url: "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
38
- isbn: "9784781990491",
39
- price: 2695,
40
- publishedAt: "2026-03-25",
41
- });
42
- });
43
-
44
- it("coverImageUrl が設定される", async () => {
45
- const body = await loadFixture("saiensu-search.html");
46
- const http = new MockHttpClient().addResponse(
47
- "https://www.saiensu.co.jp/search/",
48
- { status: 200, body },
49
- );
50
-
51
- const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
52
-
53
- assert.strictEqual(
54
- results[0].coverImageUrl,
55
- "https://www.saiensu.co.jp/bookThumbs/2026-978-4-7819-9049-1.jpg",
56
- );
57
- });
58
-
59
- it("ebookStores にサイエンス社(DRM付き)が含まれる", async () => {
60
- const body = await loadFixture("saiensu-search.html");
61
- const http = new MockHttpClient().addResponse(
62
- "https://www.saiensu.co.jp/search/",
63
- { status: 200, body },
64
- );
65
-
66
- const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
67
-
68
- assert.deepStrictEqual(results[0].ebookStores, [
69
- {
70
- name: "サイエンス社",
71
- url: "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
72
- drm: "password_pdf",
73
- },
74
- ]);
75
- });
76
-
77
- it("著者の所属・役割語を除去する", async () => {
78
- const body = await loadFixture("saiensu-search.html");
79
- const http = new MockHttpClient().addResponse(
80
- "https://www.saiensu.co.jp/search/",
81
- { status: 200, body },
82
- );
83
-
84
- const results = await saiensuAdapter.search({ title: "統計" }, makeDeps(http));
85
-
86
- assert.deepStrictEqual(results[0].authors, ["堀井俊佑"]);
87
- });
88
-
89
- it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
90
- const http = new MockHttpClient();
91
-
92
- const results = await saiensuAdapter.search({}, makeDeps(http));
93
-
94
- assert.deepStrictEqual(results, []);
95
- assert.strictEqual(http.calls.length, 0);
96
- });
97
-
98
- it("検索リクエストに keyword が含まれる", async () => {
99
- const body = await loadFixture("saiensu-search.html");
100
- const http = new MockHttpClient().addResponse(
101
- "https://www.saiensu.co.jp/search/",
102
- { status: 200, body },
103
- );
104
-
105
- await saiensuAdapter.search({ title: "意味論" }, makeDeps(http));
106
-
107
- assert.ok(http.calls[0].includes("keyword=%E6%84%8F%E5%91%B3%E8%AB%96"));
108
- });
109
- });
110
-
111
- describe("getDetail()", () => {
112
- it("詳細情報を返す", async () => {
113
- const body = await loadFixture("saiensu-detail.html");
114
- const http = new MockHttpClient().addResponse(
115
- "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
116
- { status: 200, body },
117
- );
118
-
119
- const book = await saiensuAdapter.getDetail(
120
- "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
121
- makeDeps(http),
122
- );
123
-
124
- assert.partialDeepStrictEqual(book, {
125
- title: "統計リテラシーI【電子版】 ―記述統計から推測統計へ",
126
- publisher: "サイエンス社",
127
- isbn: "9784781990491",
128
- price: 2695,
129
- publishedAt: "2026-03-25",
130
- });
131
- });
132
-
133
- it("著者の所属・役割語を除去する", async () => {
134
- const body = await loadFixture("saiensu-detail.html");
135
- const http = new MockHttpClient().addResponse(
136
- "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
137
- { status: 200, body },
138
- );
139
-
140
- const book = await saiensuAdapter.getDetail(
141
- "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
142
- makeDeps(http),
143
- );
144
-
145
- assert.deepStrictEqual(book.authors, ["堀井俊佑"]);
146
- });
147
-
148
- it("ebookStores にサイエンス社(DRM付き)が含まれる", async () => {
149
- const body = await loadFixture("saiensu-detail.html");
150
- const http = new MockHttpClient().addResponse(
151
- "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
152
- { status: 200, body },
153
- );
154
-
155
- const book = await saiensuAdapter.getDetail(
156
- "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
157
- makeDeps(http),
158
- );
159
-
160
- assert.deepStrictEqual(book.ebookStores, [
161
- {
162
- name: "サイエンス社",
163
- url: "https://www.saiensu.co.jp/search/?isbn=978-4-7819-9049-1&y=2026",
164
- drm: "password_pdf",
165
- },
166
- ]);
167
- });
168
- });
169
- });
@@ -1,174 +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 { seshopAdapter } from "../../../../src/adapters/publishers/seshop.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("seshopAdapter", () => {
21
- describe("search()", () => {
22
- it("電子書籍のみ BookRecord[] を返す(紙書籍は除外)", async () => {
23
- const body = await loadFixture("seshop-search.html");
24
- const http = new MockHttpClient().addResponse(
25
- "https://www.seshop.com/search",
26
- { status: 200, body },
27
- );
28
-
29
- const results = await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
30
-
31
- // フィクスチャには電子2件・紙1件あり、電子のみ返す
32
- assert.strictEqual(results.length, 2);
33
- assert.partialDeepStrictEqual(results[0], {
34
- title: "TypeScript入門【PDF版】",
35
- publisher: "翔泳社",
36
- url: "https://www.seshop.com/product/detail/26500",
37
- price: 3520,
38
- publishedAt: "2024-06-10",
39
- });
40
- });
41
-
42
- it("coverImageUrl が設定される", async () => {
43
- const body = await loadFixture("seshop-search.html");
44
- const http = new MockHttpClient().addResponse(
45
- "https://www.seshop.com/search",
46
- { status: 200, body },
47
- );
48
-
49
- const results = await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
50
-
51
- assert.strictEqual(
52
- results[0].coverImageUrl,
53
- "https://www.seshop.com/static/images/product/26500/L.png",
54
- );
55
- });
56
-
57
- it("ebookStores に SEshop (social DRM) が含まれる", async () => {
58
- const body = await loadFixture("seshop-search.html");
59
- const http = new MockHttpClient().addResponse(
60
- "https://www.seshop.com/search",
61
- { status: 200, body },
62
- );
63
-
64
- const results = await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
65
-
66
- assert.deepStrictEqual(results[0].ebookStores, [
67
- {
68
- name: "SEshop",
69
- url: "https://www.seshop.com/product/detail/26500",
70
- drm: "social",
71
- },
72
- ]);
73
- });
74
-
75
- it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
76
- const http = new MockHttpClient();
77
-
78
- const results = await seshopAdapter.search({}, makeDeps(http));
79
-
80
- assert.deepStrictEqual(results, []);
81
- assert.strictEqual(http.calls.length, 0);
82
- });
83
-
84
- it("検索リクエストに keyword と category_id=327 が含まれる", async () => {
85
- const body = await loadFixture("seshop-search.html");
86
- const http = new MockHttpClient().addResponse(
87
- "https://www.seshop.com/search",
88
- { status: 200, body },
89
- );
90
-
91
- await seshopAdapter.search({ title: "TypeScript" }, makeDeps(http));
92
-
93
- assert.ok(http.calls[0].includes("keyword=TypeScript"));
94
- assert.ok(http.calls[0].includes("category_id=327"));
95
- });
96
- });
97
-
98
- describe("getDetail()", () => {
99
- it("詳細情報を返す", async () => {
100
- const body = await loadFixture("seshop-detail.html");
101
- const http = new MockHttpClient().addResponse(
102
- "https://www.seshop.com/product/detail/26500",
103
- { status: 200, body },
104
- );
105
-
106
- const book = await seshopAdapter.getDetail(
107
- "https://www.seshop.com/product/detail/26500",
108
- makeDeps(http),
109
- );
110
-
111
- assert.partialDeepStrictEqual(book, {
112
- title: "TypeScript入門【PDF版】",
113
- publisher: "翔泳社",
114
- isbn: "9784798190014",
115
- price: 3520,
116
- publishedAt: "2024-06-10",
117
- });
118
- });
119
-
120
- it("複数著者を取得する", async () => {
121
- const body = await loadFixture("seshop-detail.html");
122
- const http = new MockHttpClient().addResponse(
123
- "https://www.seshop.com/product/detail/26500",
124
- { status: 200, body },
125
- );
126
-
127
- const book = await seshopAdapter.getDetail(
128
- "https://www.seshop.com/product/detail/26500",
129
- makeDeps(http),
130
- );
131
-
132
- assert.deepStrictEqual(book.authors, ["山田 太郎", "鈴木 花子"]);
133
- });
134
-
135
- it("coverImageUrl が設定される", async () => {
136
- const body = await loadFixture("seshop-detail.html");
137
- const http = new MockHttpClient().addResponse(
138
- "https://www.seshop.com/product/detail/26500",
139
- { status: 200, body },
140
- );
141
-
142
- const book = await seshopAdapter.getDetail(
143
- "https://www.seshop.com/product/detail/26500",
144
- makeDeps(http),
145
- );
146
-
147
- assert.strictEqual(
148
- book.coverImageUrl,
149
- "https://www.seshop.com/static/images/product/26500/L.png",
150
- );
151
- });
152
-
153
- it("ebookStores に SEshop (social DRM) が含まれる", async () => {
154
- const body = await loadFixture("seshop-detail.html");
155
- const http = new MockHttpClient().addResponse(
156
- "https://www.seshop.com/product/detail/26500",
157
- { status: 200, body },
158
- );
159
-
160
- const book = await seshopAdapter.getDetail(
161
- "https://www.seshop.com/product/detail/26500",
162
- makeDeps(http),
163
- );
164
-
165
- assert.deepStrictEqual(book.ebookStores, [
166
- {
167
- name: "SEshop",
168
- url: "https://www.seshop.com/product/detail/26500",
169
- drm: "social",
170
- },
171
- ]);
172
- });
173
- });
174
- });
@@ -1,172 +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 { tatsuZineAdapter } from "../../../../src/adapters/publishers/tatsu-zine.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("tatsuZineAdapter", () => {
21
- describe("search()", () => {
22
- it("検索結果から BookRecord[] を返す", async () => {
23
- const body = await loadFixture("tatsu-zine-search.html");
24
- const http = new MockHttpClient().addResponse(
25
- "https://tatsu-zine.com/books/",
26
- { status: 200, body },
27
- );
28
-
29
- const results = await tatsuZineAdapter.search({ title: "Go" }, makeDeps(http));
30
-
31
- assert.strictEqual(results.length, 2);
32
- assert.partialDeepStrictEqual(results[0], {
33
- title: "Goプログラミング実践入門",
34
- authors: ["Sau Sheong Chang", "武舎 広幸"],
35
- publisher: "達人出版会",
36
- });
37
- assert.strictEqual(results[0].url, "https://tatsu-zine.com/books/go-programming");
38
- });
39
-
40
- it("ebookStores に達人出版会(ソーシャルDRM)が含まれる", async () => {
41
- const body = await loadFixture("tatsu-zine-search.html");
42
- const http = new MockHttpClient().addResponse(
43
- "https://tatsu-zine.com/books/",
44
- { status: 200, body },
45
- );
46
-
47
- const results = await tatsuZineAdapter.search({ title: "Go" }, makeDeps(http));
48
-
49
- assert.deepStrictEqual(results[0].ebookStores, [
50
- { name: "達人出版会", url: "https://tatsu-zine.com/books/go-programming", drm: "social" },
51
- ]);
52
- });
53
-
54
- it("limit を適用する", async () => {
55
- const body = await loadFixture("tatsu-zine-search.html");
56
- const http = new MockHttpClient().addResponse(
57
- "https://tatsu-zine.com/books/",
58
- { status: 200, body },
59
- );
60
-
61
- const results = await tatsuZineAdapter.search({ title: "Go", limit: 1 }, makeDeps(http));
62
-
63
- assert.strictEqual(results.length, 1);
64
- });
65
-
66
- it("title が未指定の場合は [] を返しHTTPを呼ばない", async () => {
67
- const http = new MockHttpClient();
68
- const results = await tatsuZineAdapter.search({}, makeDeps(http));
69
-
70
- assert.deepStrictEqual(results, []);
71
- assert.strictEqual(http.calls.length, 0);
72
- });
73
-
74
- it("author のみ指定の場合も [] を返しHTTPを呼ばない", async () => {
75
- const http = new MockHttpClient();
76
- const results = await tatsuZineAdapter.search({ author: "Jesse Storimer" }, makeDeps(http));
77
-
78
- assert.deepStrictEqual(results, []);
79
- assert.strictEqual(http.calls.length, 0);
80
- });
81
-
82
- it("書籍一覧ページ全体を取得してタイトルでフィルタする", async () => {
83
- const body = await loadFixture("tatsu-zine-search.html");
84
- const http = new MockHttpClient().addResponse(
85
- "https://tatsu-zine.com/books/",
86
- { status: 200, body },
87
- );
88
-
89
- await tatsuZineAdapter.search({ title: "Go言語" }, makeDeps(http));
90
-
91
- assert.strictEqual(http.calls[0], "https://tatsu-zine.com/books/");
92
- });
93
-
94
- it("ページネーションがある場合は全ページを取得してフィルタする", async () => {
95
- const page1 = `<!DOCTYPE html><html><body>
96
- <section class="pagination">
97
- <nav class="pagination">
98
- <a class="btn-pagination" href="/books?page=2">2</a>
99
- <a class="btn-pagination" href="/books?page=2">最後へ</a>
100
- </nav>
101
- </section>
102
- <article class="book">
103
- <h3 itemprop="name"><a href="/books/page1-book">ページ1の本</a></h3>
104
- <p itemprop="author" class="author">著者A(著)</p>
105
- </article>
106
- </body></html>`;
107
- const page2 = `<!DOCTYPE html><html><body>
108
- <article class="book">
109
- <h3 itemprop="name"><a href="/books/naruhounix">なるほどUnixプロセス ― Rubyで学ぶUnixの基礎</a></h3>
110
- <p itemprop="author" class="author">Jesse Storimer(著), 島田 浩二(訳), 角谷 信太郎(訳)</p>
111
- </article>
112
- </body></html>`;
113
- const http = new MockHttpClient()
114
- .addResponse("https://tatsu-zine.com/books/", { status: 200, body: page1 })
115
- .addResponse("https://tatsu-zine.com/books?page=2", { status: 200, body: page2 });
116
-
117
- const results = await tatsuZineAdapter.search({ title: "なるほどUnix" }, makeDeps(http));
118
-
119
- assert.strictEqual(results.length, 1);
120
- assert.partialDeepStrictEqual(results[0], {
121
- title: "なるほどUnixプロセス ― Rubyで学ぶUnixの基礎",
122
- authors: ["Jesse Storimer", "島田 浩二", "角谷 信太郎"],
123
- url: "https://tatsu-zine.com/books/naruhounix",
124
- });
125
- });
126
- });
127
-
128
- describe("getDetail()", () => {
129
- it("詳細情報を返す(達人出版会は常にソーシャルDRM)", async () => {
130
- const body = await loadFixture("tatsu-zine-detail-free.html");
131
- const http = new MockHttpClient().addResponse(
132
- "https://tatsu-zine.com/books/go-programming",
133
- { status: 200, body },
134
- );
135
-
136
- const book = await tatsuZineAdapter.getDetail(
137
- "https://tatsu-zine.com/books/go-programming",
138
- makeDeps(http),
139
- );
140
-
141
- assert.partialDeepStrictEqual(book, {
142
- title: "Goプログラミング実践入門",
143
- authors: ["Sau Sheong Chang", "武舎 広幸"],
144
- publisher: "インプレス",
145
- price: 3520,
146
- });
147
- // 達人出版会は「ソーシャルDRM」と明記がなくても全書籍で購入者情報を印字
148
- assert.deepStrictEqual(book.ebookStores, [
149
- { name: "達人出版会", url: "https://tatsu-zine.com/books/go-programming", drm: "social" },
150
- ]);
151
- });
152
-
153
- it("出版社が達人出版会自身の場合はフォールバックする", async () => {
154
- const body = `<!DOCTYPE html><html><body>
155
- <h1>達人出版会刊行の本</h1>
156
- <img src="/images/books/999/cover.jpg">
157
- <dl><dt>著者</dt><dd>著者名(著)</dd><dt>定価</dt><dd>2,200円 (2,000円+税)</dd></dl>
158
- </body></html>`;
159
- const http = new MockHttpClient().addResponse(
160
- "https://tatsu-zine.com/books/some-book",
161
- { status: 200, body },
162
- );
163
-
164
- const book = await tatsuZineAdapter.getDetail(
165
- "https://tatsu-zine.com/books/some-book",
166
- makeDeps(http),
167
- );
168
-
169
- assert.strictEqual(book.publisher, "達人出版会");
170
- });
171
- });
172
- });