@zonuexe/techbook-mcp 0.1.0
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.
- package/.claude/settings.local.json +23 -0
- package/.github/workflows/test.yml +36 -0
- package/AGENTS.md +72 -0
- package/CLAUDE.md +2 -0
- package/LICENSE +661 -0
- package/README.md +154 -0
- package/dist/adapters/cache/memory-cache.d.ts +8 -0
- package/dist/adapters/cache/memory-cache.d.ts.map +1 -0
- package/dist/adapters/cache/memory-cache.js +23 -0
- package/dist/adapters/cache/memory-cache.js.map +1 -0
- package/dist/adapters/cache/null-cache.d.ts +8 -0
- package/dist/adapters/cache/null-cache.d.ts.map +1 -0
- package/dist/adapters/cache/null-cache.js +7 -0
- package/dist/adapters/cache/null-cache.js.map +1 -0
- package/dist/adapters/html/cheerio-parser.d.ts +5 -0
- package/dist/adapters/html/cheerio-parser.d.ts.map +1 -0
- package/dist/adapters/html/cheerio-parser.js +45 -0
- package/dist/adapters/html/cheerio-parser.js.map +1 -0
- package/dist/adapters/http/fetch-client.d.ts +6 -0
- package/dist/adapters/http/fetch-client.d.ts.map +1 -0
- package/dist/adapters/http/fetch-client.js +43 -0
- package/dist/adapters/http/fetch-client.js.map +1 -0
- package/dist/adapters/http/mock-client.d.ts +19 -0
- package/dist/adapters/http/mock-client.d.ts.map +1 -0
- package/dist/adapters/http/mock-client.js +59 -0
- package/dist/adapters/http/mock-client.js.map +1 -0
- package/dist/adapters/publishers/base.d.ts +24 -0
- package/dist/adapters/publishers/base.d.ts.map +1 -0
- package/dist/adapters/publishers/base.js +88 -0
- package/dist/adapters/publishers/base.js.map +1 -0
- package/dist/adapters/publishers/gihyo.d.ts +3 -0
- package/dist/adapters/publishers/gihyo.d.ts.map +1 -0
- package/dist/adapters/publishers/gihyo.js +75 -0
- package/dist/adapters/publishers/gihyo.js.map +1 -0
- package/dist/adapters/publishers/lambdanote.d.ts +3 -0
- package/dist/adapters/publishers/lambdanote.d.ts.map +1 -0
- package/dist/adapters/publishers/lambdanote.js +113 -0
- package/dist/adapters/publishers/lambdanote.js.map +1 -0
- package/dist/adapters/publishers/registry.d.ts +3 -0
- package/dist/adapters/publishers/registry.d.ts.map +1 -0
- package/dist/adapters/publishers/registry.js +11 -0
- package/dist/adapters/publishers/registry.js.map +1 -0
- package/dist/adapters/publishers/tatsu-zine.d.ts +3 -0
- package/dist/adapters/publishers/tatsu-zine.d.ts.map +1 -0
- package/dist/adapters/publishers/tatsu-zine.js +110 -0
- package/dist/adapters/publishers/tatsu-zine.js.map +1 -0
- package/dist/adapters/publishers/techbookfest.d.ts +3 -0
- package/dist/adapters/publishers/techbookfest.d.ts.map +1 -0
- package/dist/adapters/publishers/techbookfest.js +134 -0
- package/dist/adapters/publishers/techbookfest.js.map +1 -0
- package/dist/application/get-book-detail.d.ts +4 -0
- package/dist/application/get-book-detail.d.ts.map +1 -0
- package/dist/application/get-book-detail.js +9 -0
- package/dist/application/get-book-detail.js.map +1 -0
- package/dist/application/search-books.d.ts +11 -0
- package/dist/application/search-books.d.ts.map +1 -0
- package/dist/application/search-books.js +23 -0
- package/dist/application/search-books.js.map +1 -0
- package/dist/domain/book.d.ts +32 -0
- package/dist/domain/book.d.ts.map +1 -0
- package/dist/domain/book.js +2 -0
- package/dist/domain/book.js.map +1 -0
- package/dist/domain/publisher.d.ts +17 -0
- package/dist/domain/publisher.d.ts.map +1 -0
- package/dist/domain/publisher.js +2 -0
- package/dist/domain/publisher.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +12 -0
- package/dist/main.js.map +1 -0
- package/dist/mcp/server.d.ts +5 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +79 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +47 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +53 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/ports/cache.d.ts +6 -0
- package/dist/ports/cache.d.ts.map +1 -0
- package/dist/ports/cache.js +2 -0
- package/dist/ports/cache.js.map +1 -0
- package/dist/ports/html-parser.d.ts +14 -0
- package/dist/ports/html-parser.d.ts.map +1 -0
- package/dist/ports/html-parser.js +2 -0
- package/dist/ports/html-parser.js.map +1 -0
- package/dist/ports/http.d.ts +16 -0
- package/dist/ports/http.d.ts.map +1 -0
- package/dist/ports/http.js +2 -0
- package/dist/ports/http.js.map +1 -0
- package/docs/design-doc.md +365 -0
- package/flake.nix +50 -0
- package/package.json +29 -0
- package/src/adapters/cache/memory-cache.ts +31 -0
- package/src/adapters/cache/null-cache.ts +8 -0
- package/src/adapters/html/cheerio-parser.ts +49 -0
- package/src/adapters/http/fetch-client.ts +47 -0
- package/src/adapters/http/mock-client.ts +77 -0
- package/src/adapters/publishers/base.ts +129 -0
- package/src/adapters/publishers/book-tech.ts +117 -0
- package/src/adapters/publishers/born-digital.ts +158 -0
- package/src/adapters/publishers/coronasha.ts +139 -0
- package/src/adapters/publishers/gihyo.ts +120 -0
- package/src/adapters/publishers/lambdanote.ts +146 -0
- package/src/adapters/publishers/manatee.ts +112 -0
- package/src/adapters/publishers/maruzen-publishing.ts +141 -0
- package/src/adapters/publishers/optronics.ts +113 -0
- package/src/adapters/publishers/oreilly-japan.ts +138 -0
- package/src/adapters/publishers/peaks.ts +98 -0
- package/src/adapters/publishers/personal-media.ts +168 -0
- package/src/adapters/publishers/registry.ts +36 -0
- package/src/adapters/publishers/rutles.ts +161 -0
- package/src/adapters/publishers/saiensu.ts +149 -0
- package/src/adapters/publishers/seshop.ts +121 -0
- package/src/adapters/publishers/tatsu-zine.ts +129 -0
- package/src/adapters/publishers/techbookfest.ts +179 -0
- package/src/application/get-book-detail.ts +17 -0
- package/src/application/search-books.ts +39 -0
- package/src/domain/book.ts +35 -0
- package/src/domain/publisher.ts +18 -0
- package/src/main.ts +13 -0
- package/src/mcp/server.ts +103 -0
- package/src/mcp/tools.ts +54 -0
- package/src/ports/cache.ts +5 -0
- package/src/ports/html-parser.ts +15 -0
- package/src/ports/http.ts +17 -0
- package/tests/fixtures/book-tech-detail.html +51 -0
- package/tests/fixtures/book-tech-search.html +91 -0
- package/tests/fixtures/born-digital-detail.html +62 -0
- package/tests/fixtures/born-digital-search.html +51 -0
- package/tests/fixtures/coronasha-detail.html +41 -0
- package/tests/fixtures/coronasha-search.html +61 -0
- package/tests/fixtures/gihyo-detail.html +42 -0
- package/tests/fixtures/gihyo-search.json +54 -0
- package/tests/fixtures/lambdanote-search.html +66 -0
- package/tests/fixtures/manatee-detail.html +53 -0
- package/tests/fixtures/manatee-search.html +59 -0
- package/tests/fixtures/maruzen-detail.html +51 -0
- package/tests/fixtures/maruzen-search.html +60 -0
- package/tests/fixtures/optronics-detail.html +30 -0
- package/tests/fixtures/optronics-search.html +75 -0
- package/tests/fixtures/oreilly-detail.html +52 -0
- package/tests/fixtures/oreilly-ebook-list.html +53 -0
- package/tests/fixtures/peaks-detail.html +39 -0
- package/tests/fixtures/peaks-top.html +50 -0
- package/tests/fixtures/personal-media-detail.html +32 -0
- package/tests/fixtures/personal-media-search.html +39 -0
- package/tests/fixtures/rutles-detail.html +32 -0
- package/tests/fixtures/rutles-search.html +62 -0
- package/tests/fixtures/saiensu-detail.html +41 -0
- package/tests/fixtures/saiensu-search.html +65 -0
- package/tests/fixtures/seshop-detail.html +45 -0
- package/tests/fixtures/seshop-search.html +58 -0
- package/tests/fixtures/tatsu-zine-detail-free.html +22 -0
- package/tests/fixtures/tatsu-zine-search.html +24 -0
- package/tests/fixtures/techbookfest-search.json +73 -0
- package/tests/unit/adapters/publishers/book-tech.test.ts +183 -0
- package/tests/unit/adapters/publishers/born-digital.test.ts +191 -0
- package/tests/unit/adapters/publishers/coronasha.test.ts +201 -0
- package/tests/unit/adapters/publishers/gihyo.test.ts +135 -0
- package/tests/unit/adapters/publishers/lambdanote.test.ts +84 -0
- package/tests/unit/adapters/publishers/manatee.test.ts +163 -0
- package/tests/unit/adapters/publishers/maruzen-publishing.test.ts +177 -0
- package/tests/unit/adapters/publishers/optronics.test.ts +205 -0
- package/tests/unit/adapters/publishers/oreilly-japan.test.ts +191 -0
- package/tests/unit/adapters/publishers/peaks.test.ts +174 -0
- package/tests/unit/adapters/publishers/personal-media.test.ts +196 -0
- package/tests/unit/adapters/publishers/rutles.test.ts +170 -0
- package/tests/unit/adapters/publishers/saiensu.test.ts +167 -0
- package/tests/unit/adapters/publishers/seshop.test.ts +171 -0
- package/tests/unit/adapters/publishers/tatsu-zine.test.ts +130 -0
- package/tests/unit/adapters/publishers/techbookfest.test.ts +93 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { coronashaAdapter } from "../../../../src/adapters/publishers/coronasha.js";
|
|
5
|
+
import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
|
|
6
|
+
import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
|
|
7
|
+
import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
|
|
8
|
+
|
|
9
|
+
const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
|
|
10
|
+
|
|
11
|
+
function makeDeps(http: MockHttpClient) {
|
|
12
|
+
return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function loadFixture(name: string): Promise<string> {
|
|
16
|
+
return readFile(join(FIXTURES_DIR, name), "utf-8");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe("coronashaAdapter", () => {
|
|
20
|
+
describe("search()", () => {
|
|
21
|
+
it("電子版ありの書籍のみ返す(電子版なしは除外)", async () => {
|
|
22
|
+
const body = await loadFixture("coronasha-search.html");
|
|
23
|
+
const http = new MockHttpClient().addResponse(
|
|
24
|
+
"https://www.coronasha.co.jp/np/result.html",
|
|
25
|
+
{ status: 200, body },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const results = await coronashaAdapter.search({ title: "Julia" }, makeDeps(http));
|
|
29
|
+
|
|
30
|
+
// フィクスチャには電子版あり1件・電子版なし1件あり、電子版のみ返す
|
|
31
|
+
expect(results).toHaveLength(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("タイトルを tunogaki + book-title で組み立てる", async () => {
|
|
35
|
+
const body = await loadFixture("coronasha-search.html");
|
|
36
|
+
const http = new MockHttpClient().addResponse(
|
|
37
|
+
"https://www.coronasha.co.jp/np/result.html",
|
|
38
|
+
{ status: 200, body },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const results = await coronashaAdapter.search({ title: "Julia" }, makeDeps(http));
|
|
42
|
+
|
|
43
|
+
expect(results[0].title).toBe("1から始める Juliaプログラミング大全");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("著者一覧を返す", async () => {
|
|
47
|
+
const body = await loadFixture("coronasha-search.html");
|
|
48
|
+
const http = new MockHttpClient().addResponse(
|
|
49
|
+
"https://www.coronasha.co.jp/np/result.html",
|
|
50
|
+
{ status: 200, body },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const results = await coronashaAdapter.search({ title: "Julia" }, makeDeps(http));
|
|
54
|
+
|
|
55
|
+
expect(results[0].authors).toEqual(["進藤 裕之", "佐藤 建太"]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("価格・ISBN・発行日を返す", async () => {
|
|
59
|
+
const body = await loadFixture("coronasha-search.html");
|
|
60
|
+
const http = new MockHttpClient().addResponse(
|
|
61
|
+
"https://www.coronasha.co.jp/np/result.html",
|
|
62
|
+
{ status: 200, body },
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const results = await coronashaAdapter.search({ title: "Julia" }, makeDeps(http));
|
|
66
|
+
|
|
67
|
+
expect(results[0]).toMatchObject({
|
|
68
|
+
price: 3630,
|
|
69
|
+
isbn: "9784339029345",
|
|
70
|
+
publishedAt: "2023-05-01",
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("coverImageUrl が絶対URLになる", async () => {
|
|
75
|
+
const body = await loadFixture("coronasha-search.html");
|
|
76
|
+
const http = new MockHttpClient().addResponse(
|
|
77
|
+
"https://www.coronasha.co.jp/np/result.html",
|
|
78
|
+
{ status: 200, body },
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const results = await coronashaAdapter.search({ title: "Julia" }, makeDeps(http));
|
|
82
|
+
|
|
83
|
+
expect(results[0].coverImageUrl).toBe(
|
|
84
|
+
"https://www.coronasha.co.jp/np/images/isbn/9784339029345_main.jpg",
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("publisher が コロナ社 になる", async () => {
|
|
89
|
+
const body = await loadFixture("coronasha-search.html");
|
|
90
|
+
const http = new MockHttpClient().addResponse(
|
|
91
|
+
"https://www.coronasha.co.jp/np/result.html",
|
|
92
|
+
{ status: 200, body },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const results = await coronashaAdapter.search({ title: "Julia" }, makeDeps(http));
|
|
96
|
+
|
|
97
|
+
expect(results[0].publisher).toBe("コロナ社");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
101
|
+
const http = new MockHttpClient();
|
|
102
|
+
|
|
103
|
+
const results = await coronashaAdapter.search({}, makeDeps(http));
|
|
104
|
+
|
|
105
|
+
expect(results).toEqual([]);
|
|
106
|
+
expect(http.calls).toHaveLength(0);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe("getDetail()", () => {
|
|
111
|
+
it("詳細情報を返す", async () => {
|
|
112
|
+
const body = await loadFixture("coronasha-detail.html");
|
|
113
|
+
const http = new MockHttpClient().addResponse(
|
|
114
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
115
|
+
{ status: 200, body },
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const book = await coronashaAdapter.getDetail(
|
|
119
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
120
|
+
makeDeps(http),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(book).toMatchObject({
|
|
124
|
+
title: "1から始める Juliaプログラミング大全",
|
|
125
|
+
publisher: "コロナ社",
|
|
126
|
+
price: 3630,
|
|
127
|
+
publishedAt: "2023-05-01",
|
|
128
|
+
isbn: "9784339029345",
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("著者一覧を返す", async () => {
|
|
133
|
+
const body = await loadFixture("coronasha-detail.html");
|
|
134
|
+
const http = new MockHttpClient().addResponse(
|
|
135
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
136
|
+
{ status: 200, body },
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const book = await coronashaAdapter.getDetail(
|
|
140
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
141
|
+
makeDeps(http),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(book.authors).toEqual(["進藤 裕之", "佐藤 建太"]);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("ebookStores に Kindle・Kinoppy・VarsityWave eBooks が含まれる", async () => {
|
|
148
|
+
const body = await loadFixture("coronasha-detail.html");
|
|
149
|
+
const http = new MockHttpClient().addResponse(
|
|
150
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
151
|
+
{ status: 200, body },
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const book = await coronashaAdapter.getDetail(
|
|
155
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
156
|
+
makeDeps(http),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
expect(book.ebookStores).toEqual(
|
|
160
|
+
expect.arrayContaining([
|
|
161
|
+
expect.objectContaining({ name: "Kindle", drm: "drm" }),
|
|
162
|
+
expect.objectContaining({ name: "Kinoppy", drm: "drm" }),
|
|
163
|
+
expect.objectContaining({ name: "VarsityWave eBooks", drm: "drm" }),
|
|
164
|
+
]),
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("Knowledge Worker (kw.maruzen.co.jp) は ebookStores に含まれない", async () => {
|
|
169
|
+
const body = await loadFixture("coronasha-detail.html");
|
|
170
|
+
const http = new MockHttpClient().addResponse(
|
|
171
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
172
|
+
{ status: 200, body },
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const book = await coronashaAdapter.getDetail(
|
|
176
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
177
|
+
makeDeps(http),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const names = book.ebookStores.map(s => s.name);
|
|
181
|
+
expect(names).not.toContain("Knowledge Worker");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("coverImageUrl が絶対URLになる", async () => {
|
|
185
|
+
const body = await loadFixture("coronasha-detail.html");
|
|
186
|
+
const http = new MockHttpClient().addResponse(
|
|
187
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
188
|
+
{ status: 200, body },
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const book = await coronashaAdapter.getDetail(
|
|
192
|
+
"https://www.coronasha.co.jp/np/isbn/9784339029345/",
|
|
193
|
+
makeDeps(http),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
expect(book.coverImageUrl).toBe(
|
|
197
|
+
"https://www.coronasha.co.jp/np/images/isbn/9784339029345_main.jpg",
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { gihyoAdapter } from "../../../../src/adapters/publishers/gihyo.js";
|
|
5
|
+
import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
|
|
6
|
+
import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
|
|
7
|
+
import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
|
|
8
|
+
import type { HtmlParser } from "../../../../src/ports/html-parser.js";
|
|
9
|
+
|
|
10
|
+
// search() は JSON API のみ使用するためパーサー不要
|
|
11
|
+
const noopParser: HtmlParser = {
|
|
12
|
+
parse(_html) {
|
|
13
|
+
throw new Error("gihyo adapter must not call HtmlParser during search()");
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
|
|
18
|
+
|
|
19
|
+
describe("gihyoAdapter", () => {
|
|
20
|
+
async function makeSearchDeps(fixtureName: string) {
|
|
21
|
+
const body = await readFile(join(FIXTURES_DIR, fixtureName), "utf-8");
|
|
22
|
+
const http = new MockHttpClient().addResponse(
|
|
23
|
+
"https://gihyo.jp/api_gh/site/search",
|
|
24
|
+
{ status: 200, body },
|
|
25
|
+
);
|
|
26
|
+
return { http, parser: noopParser, cache: new NullCacheStore() };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function makeDetailDeps() {
|
|
30
|
+
const [apiBody, htmlBody] = await Promise.all([
|
|
31
|
+
readFile(join(FIXTURES_DIR, "gihyo-search.json"), "utf-8"),
|
|
32
|
+
readFile(join(FIXTURES_DIR, "gihyo-detail.html"), "utf-8"),
|
|
33
|
+
]);
|
|
34
|
+
const http = new MockHttpClient()
|
|
35
|
+
.addResponse("https://gihyo.jp/api_gh/site/search", { status: 200, body: apiBody })
|
|
36
|
+
.addResponse("https://gihyo.jp/book/", { status: 200, body: htmlBody });
|
|
37
|
+
return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
it("search() が JSON API レスポンスから BookRecord[] を返す", async () => {
|
|
41
|
+
const deps = await makeSearchDeps("gihyo-search.json");
|
|
42
|
+
|
|
43
|
+
const results = await gihyoAdapter.search({ title: "TypeScript", limit: 10 }, deps);
|
|
44
|
+
|
|
45
|
+
expect(results).toHaveLength(2);
|
|
46
|
+
expect(results[0]).toMatchObject({
|
|
47
|
+
title: "プロを目指す人のためのTypeScript入門 安全なコードの書き方から高度な型の使い方まで",
|
|
48
|
+
authors: ["uhyo"],
|
|
49
|
+
publisher: "技術評論社",
|
|
50
|
+
isbn: "9784297128152",
|
|
51
|
+
price: 3740,
|
|
52
|
+
publishedAt: "2022-04-01",
|
|
53
|
+
});
|
|
54
|
+
expect(results[0].url).toBe("https://gihyo.jp/book/2022/978-4-297-12815-2");
|
|
55
|
+
expect(results[0].coverImageUrl).toBe(
|
|
56
|
+
"https://gihyo.jp/assets/images/cover/2022/9784297128152.jpg",
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("サブタイトルなし書籍はタイトルのみになる", async () => {
|
|
61
|
+
const deps = await makeSearchDeps("gihyo-search.json");
|
|
62
|
+
const results = await gihyoAdapter.search({ title: "TypeScript" }, deps);
|
|
63
|
+
|
|
64
|
+
const book = results.find(b => b.isbn === "9784297136010");
|
|
65
|
+
expect(book?.title).toBe("TypeScriptとReact/Next.jsでつくる実践Webアプリケーション開発");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("複数著者が配列になる", async () => {
|
|
69
|
+
const deps = await makeSearchDeps("gihyo-search.json");
|
|
70
|
+
const results = await gihyoAdapter.search({ title: "TypeScript" }, deps);
|
|
71
|
+
|
|
72
|
+
const book = results.find(b => b.isbn === "9784297136010");
|
|
73
|
+
expect(book?.authors).toEqual(["手島拓也", "吉田健人", "高林佳稀"]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
77
|
+
const http = new MockHttpClient();
|
|
78
|
+
const deps = { http, parser: noopParser, cache: new NullCacheStore() };
|
|
79
|
+
|
|
80
|
+
const results = await gihyoAdapter.search({}, deps);
|
|
81
|
+
|
|
82
|
+
expect(results).toEqual([]);
|
|
83
|
+
expect(http.calls).toHaveLength(0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("search() のリクエストURLにクエリが含まれる", async () => {
|
|
87
|
+
const deps = await makeSearchDeps("gihyo-search.json");
|
|
88
|
+
await gihyoAdapter.search({ title: "TypeScript" }, deps);
|
|
89
|
+
|
|
90
|
+
expect(deps.http.calls[0]).toContain("search=TypeScript");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("author クエリが API に渡される", async () => {
|
|
94
|
+
const deps = await makeSearchDeps("gihyo-search.json");
|
|
95
|
+
await gihyoAdapter.search({ author: "uhyo" }, deps);
|
|
96
|
+
|
|
97
|
+
expect(deps.http.calls[0]).toContain("search=uhyo");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("getDetail()", () => {
|
|
101
|
+
it("ebookStores にソーシャルDRMとDRM付きが含まれる", async () => {
|
|
102
|
+
const deps = await makeDetailDeps();
|
|
103
|
+
const book = await gihyoAdapter.getDetail(
|
|
104
|
+
"https://gihyo.jp/book/2022/978-4-297-12815-2",
|
|
105
|
+
deps,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(book.ebookStores).toBeDefined();
|
|
109
|
+
const socialStores = book.ebookStores!.filter(s => s.drm === "social");
|
|
110
|
+
const drmStores = book.ebookStores!.filter(s => s.drm === "drm");
|
|
111
|
+
|
|
112
|
+
// Gihyo Digital Publishing は見えない購入者情報を埋め込むソーシャルDRM
|
|
113
|
+
expect(socialStores).toHaveLength(1);
|
|
114
|
+
expect(socialStores[0]).toMatchObject({
|
|
115
|
+
name: "Gihyo Digital Publishing",
|
|
116
|
+
drm: "social",
|
|
117
|
+
url: expect.stringContaining("gihyo.jp/dp/ebook/"),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(drmStores.map(s => s.name)).toEqual(
|
|
121
|
+
expect.arrayContaining(["Kindle", "楽天Kobo", "BookLive", "honto"]),
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("ASIN が Amazon リンクから抽出される", async () => {
|
|
126
|
+
const deps = await makeDetailDeps();
|
|
127
|
+
const book = await gihyoAdapter.getDetail(
|
|
128
|
+
"https://gihyo.jp/book/2022/978-4-297-12815-2",
|
|
129
|
+
deps,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(book.asin).toBe("B09YGZ18ZK");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { lambdanoteAdapter } from "../../../../src/adapters/publishers/lambdanote.js";
|
|
5
|
+
import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
|
|
6
|
+
import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
|
|
7
|
+
import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
|
|
8
|
+
|
|
9
|
+
const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
|
|
10
|
+
|
|
11
|
+
function makeDeps(http: MockHttpClient) {
|
|
12
|
+
return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("lambdanoteAdapter", () => {
|
|
16
|
+
it("search() が HTML 検索結果から BookRecord[] を返す", async () => {
|
|
17
|
+
const body = await readFile(join(FIXTURES_DIR, "lambdanote-search.html"), "utf-8");
|
|
18
|
+
const http = new MockHttpClient().addResponse(
|
|
19
|
+
"https://www.lambdanote.com/search",
|
|
20
|
+
{ status: 200, body },
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const results = await lambdanoteAdapter.search({ title: "Go" }, makeDeps(http));
|
|
24
|
+
|
|
25
|
+
expect(results).toHaveLength(2);
|
|
26
|
+
expect(results[0]).toMatchObject({
|
|
27
|
+
title: "Goならわかるシステムプログラミング 第2版",
|
|
28
|
+
publisher: "ラムダノート",
|
|
29
|
+
price: 3960,
|
|
30
|
+
});
|
|
31
|
+
expect(results[0].url).toBe("https://www.lambdanote.com/products/go-2");
|
|
32
|
+
expect(results[0].coverImageUrl).toContain("go2_small.jpg");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("2件目の書籍も正しく取得できる", async () => {
|
|
36
|
+
const body = await readFile(join(FIXTURES_DIR, "lambdanote-search.html"), "utf-8");
|
|
37
|
+
const http = new MockHttpClient().addResponse(
|
|
38
|
+
"https://www.lambdanote.com/search",
|
|
39
|
+
{ status: 200, body },
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const results = await lambdanoteAdapter.search({ title: "Go" }, makeDeps(http));
|
|
43
|
+
|
|
44
|
+
expect(results[1]).toMatchObject({
|
|
45
|
+
title: "プログラミング言語Go",
|
|
46
|
+
price: 4400,
|
|
47
|
+
});
|
|
48
|
+
expect(results[1].url).toBe("https://www.lambdanote.com/products/gopl");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("limit を適用する", async () => {
|
|
52
|
+
const body = await readFile(join(FIXTURES_DIR, "lambdanote-search.html"), "utf-8");
|
|
53
|
+
const http = new MockHttpClient().addResponse(
|
|
54
|
+
"https://www.lambdanote.com/search",
|
|
55
|
+
{ status: 200, body },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const results = await lambdanoteAdapter.search({ title: "Go", limit: 1 }, makeDeps(http));
|
|
59
|
+
|
|
60
|
+
expect(results).toHaveLength(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("結果ゼロの場合は [] を返す", async () => {
|
|
64
|
+
const body = `<!DOCTYPE html><html><body>
|
|
65
|
+
<ul class="search-results__list"></ul>
|
|
66
|
+
</body></html>`;
|
|
67
|
+
const http = new MockHttpClient().addResponse(
|
|
68
|
+
"https://www.lambdanote.com/search",
|
|
69
|
+
{ status: 200, body },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const results = await lambdanoteAdapter.search({ title: "存在しない本" }, makeDeps(http));
|
|
73
|
+
|
|
74
|
+
expect(results).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
78
|
+
const http = new MockHttpClient();
|
|
79
|
+
const results = await lambdanoteAdapter.search({}, makeDeps(http));
|
|
80
|
+
|
|
81
|
+
expect(results).toEqual([]);
|
|
82
|
+
expect(http.calls).toHaveLength(0);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { manateeAdapter } from "../../../../src/adapters/publishers/manatee.js";
|
|
5
|
+
import { MockHttpClient } from "../../../../src/adapters/http/mock-client.js";
|
|
6
|
+
import { CheerioHtmlParser } from "../../../../src/adapters/html/cheerio-parser.js";
|
|
7
|
+
import { NullCacheStore } from "../../../../src/adapters/cache/null-cache.js";
|
|
8
|
+
|
|
9
|
+
const FIXTURES_DIR = join(import.meta.dirname, "../../../fixtures");
|
|
10
|
+
|
|
11
|
+
function makeDeps(http: MockHttpClient) {
|
|
12
|
+
return { http, parser: new CheerioHtmlParser(), cache: new NullCacheStore() };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function loadFixture(name: string): Promise<string> {
|
|
16
|
+
return readFile(join(FIXTURES_DIR, name), "utf-8");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe("manateeAdapter", () => {
|
|
20
|
+
describe("search()", () => {
|
|
21
|
+
it("検索結果から BookRecord[] を返す", async () => {
|
|
22
|
+
const body = await loadFixture("manatee-search.html");
|
|
23
|
+
const http = new MockHttpClient().addResponse(
|
|
24
|
+
"https://book.mynavi.jp/manatee/books/",
|
|
25
|
+
{ status: 200, body },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const results = await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
|
|
29
|
+
|
|
30
|
+
expect(results).toHaveLength(3);
|
|
31
|
+
expect(results[0]).toMatchObject({
|
|
32
|
+
title: "現場で使えるTypeScript 詳解実践ガイド",
|
|
33
|
+
publisher: "マナティ",
|
|
34
|
+
url: "https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
35
|
+
price: 2948,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("ebookStores にマナティ(ソーシャルDRM)が含まれる", async () => {
|
|
40
|
+
const body = await loadFixture("manatee-search.html");
|
|
41
|
+
const http = new MockHttpClient().addResponse(
|
|
42
|
+
"https://book.mynavi.jp/manatee/books/",
|
|
43
|
+
{ status: 200, body },
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const results = await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
|
|
47
|
+
|
|
48
|
+
expect(results[0].ebookStores).toEqual([
|
|
49
|
+
{
|
|
50
|
+
name: "マナティ",
|
|
51
|
+
url: "https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
52
|
+
drm: "social",
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("coverImageUrl が設定される", async () => {
|
|
58
|
+
const body = await loadFixture("manatee-search.html");
|
|
59
|
+
const http = new MockHttpClient().addResponse(
|
|
60
|
+
"https://book.mynavi.jp/manatee/books/",
|
|
61
|
+
{ status: 200, body },
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const results = await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
|
|
65
|
+
|
|
66
|
+
expect(results[0].coverImageUrl).toBe(
|
|
67
|
+
"https://book.mynavi.jp/files/topics/142711_ext_06_0.jpg",
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("limit を適用する", async () => {
|
|
72
|
+
const body = await loadFixture("manatee-search.html");
|
|
73
|
+
const http = new MockHttpClient().addResponse(
|
|
74
|
+
"https://book.mynavi.jp/manatee/books/",
|
|
75
|
+
{ status: 200, body },
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const results = await manateeAdapter.search({ title: "TypeScript", limit: 2 }, makeDeps(http));
|
|
79
|
+
|
|
80
|
+
expect(results).toHaveLength(2);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
84
|
+
const http = new MockHttpClient();
|
|
85
|
+
|
|
86
|
+
const results = await manateeAdapter.search({}, makeDeps(http));
|
|
87
|
+
|
|
88
|
+
expect(results).toEqual([]);
|
|
89
|
+
expect(http.calls).toHaveLength(0);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("検索リクエストに topics_keyword が含まれる", async () => {
|
|
93
|
+
const body = await loadFixture("manatee-search.html");
|
|
94
|
+
const http = new MockHttpClient().addResponse(
|
|
95
|
+
"https://book.mynavi.jp/manatee/books/",
|
|
96
|
+
{ status: 200, body },
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
await manateeAdapter.search({ title: "TypeScript" }, makeDeps(http));
|
|
100
|
+
|
|
101
|
+
expect(http.calls[0]).toContain("topics_keyword=TypeScript");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("getDetail()", () => {
|
|
106
|
+
it("詳細情報を返す", async () => {
|
|
107
|
+
const body = await loadFixture("manatee-detail.html");
|
|
108
|
+
const http = new MockHttpClient().addResponse(
|
|
109
|
+
"https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
110
|
+
{ status: 200, body },
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const book = await manateeAdapter.getDetail(
|
|
114
|
+
"https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
115
|
+
makeDeps(http),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(book).toMatchObject({
|
|
119
|
+
title: "現場で使えるTypeScript 詳解実践ガイド",
|
|
120
|
+
publisher: "マイナビ出版",
|
|
121
|
+
isbn: "9784839984274",
|
|
122
|
+
price: 2948,
|
|
123
|
+
publishedAt: "2024-03-22",
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("著者が配列で返される", async () => {
|
|
128
|
+
const body = await loadFixture("manatee-detail.html");
|
|
129
|
+
const http = new MockHttpClient().addResponse(
|
|
130
|
+
"https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
131
|
+
{ status: 200, body },
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const book = await manateeAdapter.getDetail(
|
|
135
|
+
"https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
136
|
+
makeDeps(http),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(book.authors).toEqual(["菅原浩之", "CodeMafia", "外村将大"]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("ebookStores にマナティ(ソーシャルDRM)が含まれる", async () => {
|
|
143
|
+
const body = await loadFixture("manatee-detail.html");
|
|
144
|
+
const http = new MockHttpClient().addResponse(
|
|
145
|
+
"https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
146
|
+
{ status: 200, body },
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const book = await manateeAdapter.getDetail(
|
|
150
|
+
"https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
151
|
+
makeDeps(http),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
expect(book.ebookStores).toEqual([
|
|
155
|
+
{
|
|
156
|
+
name: "マナティ",
|
|
157
|
+
url: "https://book.mynavi.jp/manatee/books/detail/id=142711",
|
|
158
|
+
drm: "social",
|
|
159
|
+
},
|
|
160
|
+
]);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|