@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,174 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { peaksAdapter } from "../../../../src/adapters/publishers/peaks.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("peaksAdapter", () => {
|
|
20
|
+
describe("search()", () => {
|
|
21
|
+
it("タイトルキーワードにマッチする BookRecord[] を返す", async () => {
|
|
22
|
+
const body = await loadFixture("peaks-top.html");
|
|
23
|
+
const http = new MockHttpClient().addResponse(
|
|
24
|
+
"https://peaks.cc",
|
|
25
|
+
{ status: 200, body },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const results = await peaksAdapter.search({ title: "Android" }, makeDeps(http));
|
|
29
|
+
|
|
30
|
+
expect(results).toHaveLength(1);
|
|
31
|
+
expect(results[0]).toMatchObject({
|
|
32
|
+
title: "チームで育てるAndroidアプリ設計",
|
|
33
|
+
publisher: "PEAKS",
|
|
34
|
+
url: "https://peaks.cc/books/architecture_with_team",
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("coverImageUrl が設定される", async () => {
|
|
39
|
+
const body = await loadFixture("peaks-top.html");
|
|
40
|
+
const http = new MockHttpClient().addResponse(
|
|
41
|
+
"https://peaks.cc",
|
|
42
|
+
{ status: 200, body },
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const results = await peaksAdapter.search({ title: "Android" }, makeDeps(http));
|
|
46
|
+
|
|
47
|
+
expect(results[0].coverImageUrl).toBe(
|
|
48
|
+
"https://peaks-img.s3-ap-northeast-1.amazonaws.com/architecture_with_team_book_cover_alpha.png",
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("ebookStores に PEAKS (DRMフリー) が含まれる", async () => {
|
|
53
|
+
const body = await loadFixture("peaks-top.html");
|
|
54
|
+
const http = new MockHttpClient().addResponse(
|
|
55
|
+
"https://peaks.cc",
|
|
56
|
+
{ status: 200, body },
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const results = await peaksAdapter.search({ title: "Android" }, makeDeps(http));
|
|
60
|
+
|
|
61
|
+
expect(results[0].ebookStores).toEqual([
|
|
62
|
+
{
|
|
63
|
+
name: "PEAKS",
|
|
64
|
+
url: "https://peaks.cc/books/architecture_with_team",
|
|
65
|
+
drm: "free",
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("title が空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
71
|
+
const http = new MockHttpClient();
|
|
72
|
+
|
|
73
|
+
const results = await peaksAdapter.search({}, makeDeps(http));
|
|
74
|
+
|
|
75
|
+
expect(results).toEqual([]);
|
|
76
|
+
expect(http.calls).toHaveLength(0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("author のみの検索は [] を返しHTTPを呼ばない", async () => {
|
|
80
|
+
const http = new MockHttpClient();
|
|
81
|
+
|
|
82
|
+
const results = await peaksAdapter.search({ author: "伊藤" }, makeDeps(http));
|
|
83
|
+
|
|
84
|
+
expect(results).toEqual([]);
|
|
85
|
+
expect(http.calls).toHaveLength(0);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("マッチしないキーワードは空配列を返す", async () => {
|
|
89
|
+
const body = await loadFixture("peaks-top.html");
|
|
90
|
+
const http = new MockHttpClient().addResponse(
|
|
91
|
+
"https://peaks.cc",
|
|
92
|
+
{ status: 200, body },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const results = await peaksAdapter.search({ title: "Python" }, makeDeps(http));
|
|
96
|
+
|
|
97
|
+
expect(results).toEqual([]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("getDetail()", () => {
|
|
102
|
+
it("詳細情報を返す", async () => {
|
|
103
|
+
const body = await loadFixture("peaks-detail.html");
|
|
104
|
+
const http = new MockHttpClient().addResponse(
|
|
105
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
106
|
+
{ status: 200, body },
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const book = await peaksAdapter.getDetail(
|
|
110
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
111
|
+
makeDeps(http),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(book).toMatchObject({
|
|
115
|
+
title: "Jestではじめるテスト入門",
|
|
116
|
+
publisher: "PEAKS",
|
|
117
|
+
price: 2900,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("複数著者を取得し末尾カンマを除去する", async () => {
|
|
122
|
+
const body = await loadFixture("peaks-detail.html");
|
|
123
|
+
const http = new MockHttpClient().addResponse(
|
|
124
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
125
|
+
{ status: 200, body },
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const book = await peaksAdapter.getDetail(
|
|
129
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
130
|
+
makeDeps(http),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
expect(book.authors).toEqual(["伊藤 貴之", "椎葉 光行"]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("coverImageUrl が設定される", async () => {
|
|
137
|
+
const body = await loadFixture("peaks-detail.html");
|
|
138
|
+
const http = new MockHttpClient().addResponse(
|
|
139
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
140
|
+
{ status: 200, body },
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const book = await peaksAdapter.getDetail(
|
|
144
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
145
|
+
makeDeps(http),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect(book.coverImageUrl).toBe(
|
|
149
|
+
"https://peaks-img.s3-ap-northeast-1.amazonaws.com/testing_with_jest_twittercard.png",
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("ebookStores に PEAKS (DRMフリー) が含まれる", async () => {
|
|
154
|
+
const body = await loadFixture("peaks-detail.html");
|
|
155
|
+
const http = new MockHttpClient().addResponse(
|
|
156
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
157
|
+
{ status: 200, body },
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const book = await peaksAdapter.getDetail(
|
|
161
|
+
"https://peaks.cc/books/testing_with_jest",
|
|
162
|
+
makeDeps(http),
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(book.ebookStores).toEqual([
|
|
166
|
+
{
|
|
167
|
+
name: "PEAKS",
|
|
168
|
+
url: "https://peaks.cc/books/testing_with_jest",
|
|
169
|
+
drm: "free",
|
|
170
|
+
},
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { personalMediaAdapter } from "../../../../src/adapters/publishers/personal-media.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("personalMediaAdapter", () => {
|
|
20
|
+
describe("search()", () => {
|
|
21
|
+
it("タイトルキーワードに一致する書籍のみ返す", async () => {
|
|
22
|
+
const body = await loadFixture("personal-media-search.html");
|
|
23
|
+
const http = new MockHttpClient().addResponse(
|
|
24
|
+
"https://www.personal-media.co.jp/webshop/book/",
|
|
25
|
+
{ status: 200, body },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const results = await personalMediaAdapter.search({ title: "TRON" }, makeDeps(http));
|
|
29
|
+
|
|
30
|
+
// フィクスチャには TRON 含む2件・含まない1件あり
|
|
31
|
+
expect(results).toHaveLength(2);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("書籍タイトルが正しく取得される", async () => {
|
|
35
|
+
const body = await loadFixture("personal-media-search.html");
|
|
36
|
+
const http = new MockHttpClient().addResponse(
|
|
37
|
+
"https://www.personal-media.co.jp/webshop/book/",
|
|
38
|
+
{ status: 200, body },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const results = await personalMediaAdapter.search({ title: "TRON" }, makeDeps(http));
|
|
42
|
+
|
|
43
|
+
expect(results[0].title).toBe("μITRON4.0標準ガイドブック(PDF版)");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("税込価格が取得される", async () => {
|
|
47
|
+
const body = await loadFixture("personal-media-search.html");
|
|
48
|
+
const http = new MockHttpClient().addResponse(
|
|
49
|
+
"https://www.personal-media.co.jp/webshop/book/",
|
|
50
|
+
{ status: 200, body },
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const results = await personalMediaAdapter.search({ title: "TRON" }, makeDeps(http));
|
|
54
|
+
|
|
55
|
+
expect(results[0].price).toBe(2585);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("url が書籍詳細ページの絶対URLになる", async () => {
|
|
59
|
+
const body = await loadFixture("personal-media-search.html");
|
|
60
|
+
const http = new MockHttpClient().addResponse(
|
|
61
|
+
"https://www.personal-media.co.jp/webshop/book/",
|
|
62
|
+
{ status: 200, body },
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const results = await personalMediaAdapter.search({ title: "TRON" }, makeDeps(http));
|
|
66
|
+
|
|
67
|
+
expect(results[0].url).toBe(
|
|
68
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("publisher が パーソナルメディア になる", async () => {
|
|
73
|
+
const body = await loadFixture("personal-media-search.html");
|
|
74
|
+
const http = new MockHttpClient().addResponse(
|
|
75
|
+
"https://www.personal-media.co.jp/webshop/book/",
|
|
76
|
+
{ status: 200, body },
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const results = await personalMediaAdapter.search({ title: "TRON" }, makeDeps(http));
|
|
80
|
+
|
|
81
|
+
expect(results[0].publisher).toBe("パーソナルメディア");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("title が空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
85
|
+
const http = new MockHttpClient();
|
|
86
|
+
|
|
87
|
+
const results = await personalMediaAdapter.search({}, makeDeps(http));
|
|
88
|
+
|
|
89
|
+
expect(results).toEqual([]);
|
|
90
|
+
expect(http.calls).toHaveLength(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("author のみ指定の場合も [] を返しHTTPを呼ばない", async () => {
|
|
94
|
+
const http = new MockHttpClient();
|
|
95
|
+
|
|
96
|
+
const results = await personalMediaAdapter.search({ author: "坂村健" }, makeDeps(http));
|
|
97
|
+
|
|
98
|
+
expect(results).toEqual([]);
|
|
99
|
+
expect(http.calls).toHaveLength(0);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("getDetail()", () => {
|
|
104
|
+
it("タイトルを返す", async () => {
|
|
105
|
+
const body = await loadFixture("personal-media-detail.html");
|
|
106
|
+
const http = new MockHttpClient().addResponse(
|
|
107
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
108
|
+
{ status: 200, body },
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const book = await personalMediaAdapter.getDetail(
|
|
112
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
113
|
+
makeDeps(http),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
expect(book.title).toBe("μITRON4.0標準ガイドブック");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("著者名から役割語を除去して返す", async () => {
|
|
120
|
+
const body = await loadFixture("personal-media-detail.html");
|
|
121
|
+
const http = new MockHttpClient().addResponse(
|
|
122
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
123
|
+
{ status: 200, body },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const book = await personalMediaAdapter.getDetail(
|
|
127
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
128
|
+
makeDeps(http),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(book.authors).toEqual(["坂村 健", "社団法人トロン協会"]);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("価格・ISBN・発行日を返す", async () => {
|
|
135
|
+
const body = await loadFixture("personal-media-detail.html");
|
|
136
|
+
const http = new MockHttpClient().addResponse(
|
|
137
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
138
|
+
{ status: 200, body },
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const book = await personalMediaAdapter.getDetail(
|
|
142
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
143
|
+
makeDeps(http),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(book).toMatchObject({
|
|
147
|
+
price: 3520,
|
|
148
|
+
isbn: "9784893621917",
|
|
149
|
+
publishedAt: "2001-11-01",
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("coverImageUrl が絶対URLになる", async () => {
|
|
154
|
+
const body = await loadFixture("personal-media-detail.html");
|
|
155
|
+
const http = new MockHttpClient().addResponse(
|
|
156
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
157
|
+
{ status: 200, body },
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const book = await personalMediaAdapter.getDetail(
|
|
161
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
162
|
+
makeDeps(http),
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(book.coverImageUrl).toBe(
|
|
166
|
+
"https://www.personal-media.co.jp/book/tron/images/191_l.jpg",
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("ebookStores に PDF版(social)と Smooth Reader版(drm)が含まれる", async () => {
|
|
171
|
+
const body = await loadFixture("personal-media-detail.html");
|
|
172
|
+
const http = new MockHttpClient().addResponse(
|
|
173
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
174
|
+
{ status: 200, body },
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const book = await personalMediaAdapter.getDetail(
|
|
178
|
+
"https://www.personal-media.co.jp/book/tron/191.html",
|
|
179
|
+
makeDeps(http),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(book.ebookStores).toEqual([
|
|
183
|
+
{
|
|
184
|
+
name: "パーソナルメディア",
|
|
185
|
+
url: "https://www.personal-media.co.jp/webshop/book/20191.html",
|
|
186
|
+
drm: "social",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "Smooth Reader",
|
|
190
|
+
url: "https://www.personal-media.co.jp/smoothreader/store/tron/191.html",
|
|
191
|
+
drm: "drm",
|
|
192
|
+
},
|
|
193
|
+
]);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { rutlesAdapter } from "../../../../src/adapters/publishers/rutles.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("rutlesAdapter", () => {
|
|
20
|
+
describe("search()", () => {
|
|
21
|
+
it("【電子版】のみ BookRecord[] を返す(紙書籍は除外)", async () => {
|
|
22
|
+
const body = await loadFixture("rutles-search.html");
|
|
23
|
+
const http = new MockHttpClient().addResponse(
|
|
24
|
+
"https://shop.rutles.net/",
|
|
25
|
+
{ status: 200, body },
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const results = await rutlesAdapter.search({ title: "C言語" }, makeDeps(http));
|
|
29
|
+
|
|
30
|
+
// フィクスチャには電子2件・紙1件、電子のみ返す
|
|
31
|
+
expect(results).toHaveLength(2);
|
|
32
|
+
expect(results[0]).toMatchObject({
|
|
33
|
+
title: "【電子版】C言語3Dゲームプログラミング教室",
|
|
34
|
+
publisher: "ラトルズ",
|
|
35
|
+
url: "https://shop.rutles.net/?pid=173173393",
|
|
36
|
+
price: 3168,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("coverImageUrl が設定される", async () => {
|
|
41
|
+
const body = await loadFixture("rutles-search.html");
|
|
42
|
+
const http = new MockHttpClient().addResponse(
|
|
43
|
+
"https://shop.rutles.net/",
|
|
44
|
+
{ status: 200, body },
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const results = await rutlesAdapter.search({ title: "C言語" }, makeDeps(http));
|
|
48
|
+
|
|
49
|
+
expect(results[0].coverImageUrl).toBe(
|
|
50
|
+
"https://img21.shop-pro.jp/PA01496/800/product/173173393_th.jpg",
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("ebookStores にラトルズ(DRMフリー)が含まれる", async () => {
|
|
55
|
+
const body = await loadFixture("rutles-search.html");
|
|
56
|
+
const http = new MockHttpClient().addResponse(
|
|
57
|
+
"https://shop.rutles.net/",
|
|
58
|
+
{ status: 200, body },
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const results = await rutlesAdapter.search({ title: "C言語" }, makeDeps(http));
|
|
62
|
+
|
|
63
|
+
expect(results[0].ebookStores).toEqual([
|
|
64
|
+
{
|
|
65
|
+
name: "ラトルズ",
|
|
66
|
+
url: "https://shop.rutles.net/?pid=173173393",
|
|
67
|
+
drm: "free",
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("title も author も空の場合は [] を返しHTTPを呼ばない", async () => {
|
|
73
|
+
const http = new MockHttpClient();
|
|
74
|
+
|
|
75
|
+
const results = await rutlesAdapter.search({}, makeDeps(http));
|
|
76
|
+
|
|
77
|
+
expect(results).toEqual([]);
|
|
78
|
+
expect(http.calls).toHaveLength(0);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("検索URLに EUC-JP エンコードされたキーワードが含まれる", async () => {
|
|
82
|
+
const body = await loadFixture("rutles-search.html");
|
|
83
|
+
const http = new MockHttpClient().addResponse(
|
|
84
|
+
"https://shop.rutles.net/",
|
|
85
|
+
{ status: 200, body },
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
await rutlesAdapter.search({ title: "言語" }, makeDeps(http));
|
|
89
|
+
|
|
90
|
+
// "言語" の EUC-JP エンコード = %B8%C0%B8%EC
|
|
91
|
+
expect(http.calls[0]).toContain("%B8%C0%B8%EC");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("getDetail()", () => {
|
|
96
|
+
it("詳細情報を返す", async () => {
|
|
97
|
+
const body = await loadFixture("rutles-detail.html");
|
|
98
|
+
const http = new MockHttpClient().addResponse(
|
|
99
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
100
|
+
{ status: 200, body },
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const book = await rutlesAdapter.getDetail(
|
|
104
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
105
|
+
makeDeps(http),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
expect(book).toMatchObject({
|
|
109
|
+
title: "【電子版】C言語3Dゲームプログラミング教室",
|
|
110
|
+
publisher: "ラトルズ",
|
|
111
|
+
isbn: "9784899774211",
|
|
112
|
+
price: 3168,
|
|
113
|
+
publishedAt: "2014-10-25",
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("著者の役割語・所属を除去する", async () => {
|
|
118
|
+
const body = await loadFixture("rutles-detail.html");
|
|
119
|
+
const http = new MockHttpClient().addResponse(
|
|
120
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
121
|
+
{ status: 200, body },
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const book = await rutlesAdapter.getDetail(
|
|
125
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
126
|
+
makeDeps(http),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(book.authors).toEqual(["大槻有一郎", "山田巧"]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("coverImageUrl が設定される", async () => {
|
|
133
|
+
const body = await loadFixture("rutles-detail.html");
|
|
134
|
+
const http = new MockHttpClient().addResponse(
|
|
135
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
136
|
+
{ status: 200, body },
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const book = await rutlesAdapter.getDetail(
|
|
140
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
141
|
+
makeDeps(http),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(book.coverImageUrl).toBe(
|
|
145
|
+
"https://img21.shop-pro.jp/PA01496/800/product/173173393.jpg",
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("ebookStores にラトルズ(DRMフリー)が含まれる", async () => {
|
|
150
|
+
const body = await loadFixture("rutles-detail.html");
|
|
151
|
+
const http = new MockHttpClient().addResponse(
|
|
152
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
153
|
+
{ status: 200, body },
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const book = await rutlesAdapter.getDetail(
|
|
157
|
+
"https://shop.rutles.net/?pid=173173393",
|
|
158
|
+
makeDeps(http),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(book.ebookStores).toEqual([
|
|
162
|
+
{
|
|
163
|
+
name: "ラトルズ",
|
|
164
|
+
url: "https://shop.rutles.net/?pid=173173393",
|
|
165
|
+
drm: "free",
|
|
166
|
+
},
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|