mcp-wordpress 1.2.2 → 1.3.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/README.md +210 -182
- package/dist/cache/CacheInvalidation.d.ts +3 -3
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +119 -119
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +5 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +26 -16
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +29 -29
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/CacheInvalidation.test.js +96 -94
- package/dist/cache/__tests__/CacheInvalidation.test.js.map +1 -1
- package/dist/cache/__tests__/CacheManager.test.js +113 -113
- package/dist/cache/__tests__/CacheManager.test.js.map +1 -1
- package/dist/cache/__tests__/CachedWordPressClient.test.js +102 -99
- package/dist/cache/__tests__/CachedWordPressClient.test.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +98 -95
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +7 -7
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +4 -4
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +4 -4
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +55 -51
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +10 -10
- package/dist/client/api.js +158 -158
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts +2 -2
- package/dist/client/auth.js +72 -72
- package/dist/client/managers/AuthenticationManager.d.ts +2 -2
- package/dist/client/managers/AuthenticationManager.js +46 -46
- package/dist/client/managers/BaseManager.d.ts +1 -1
- package/dist/client/managers/BaseManager.js +9 -9
- package/dist/client/managers/RequestManager.d.ts +5 -3
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +39 -19
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/index.d.ts +3 -3
- package/dist/client/managers/index.js +3 -3
- package/dist/config/ConfigurationSchema.d.ts +2 -2
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +40 -40
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -2
- package/dist/config/ServerConfiguration.js +35 -35
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +296 -255
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +60 -51
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/docs/index.d.ts +3 -3
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/mcp-wordpress-1.3.0.tgz +0 -0
- package/dist/performance/MetricsCollector.d.ts +3 -3
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +33 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +12 -12
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +200 -154
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +5 -5
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +53 -52
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +6 -6
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/security/InputValidator.d.ts +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +111 -88
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +5 -5
- package/dist/security/SecurityConfig.js +92 -92
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +4 -4
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +35 -32
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/tools/BaseToolManager.js +5 -5
- package/dist/tools/auth.d.ts +2 -2
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +32 -31
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +71 -71
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +2 -2
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +79 -79
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/index.d.ts +10 -10
- package/dist/tools/index.js +10 -10
- package/dist/tools/media.d.ts +2 -2
- package/dist/tools/media.js +80 -80
- package/dist/tools/pages.d.ts +2 -2
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +75 -75
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +1 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +311 -287
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts +2 -2
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +94 -94
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +2 -2
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +60 -60
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +2 -2
- package/dist/tools/taxonomies.js +89 -89
- package/dist/tools/users.d.ts +2 -2
- package/dist/tools/users.js +68 -68
- package/dist/tools/users.js.map +1 -1
- package/dist/types/client.d.ts +13 -13
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +12 -12
- package/dist/types/client.js.map +1 -1
- package/dist/types/index.d.ts +19 -19
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/mcp.d.ts +7 -7
- package/dist/types/wordpress.d.ts +21 -21
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/utils/debug.d.ts +2 -2
- package/dist/utils/debug.js +28 -28
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +13 -13
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js +5 -5
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +41 -31
- package/dist/utils/validation.js.map +1 -1
- package/docs/CACHING.md +36 -2
- package/docs/DOCKER.md +24 -18
- package/docs/PERFORMANCE_MONITORING.md +49 -1
- package/docs/SECURITY_TESTING.md +30 -1
- package/docs/api/README.md +9 -1
- package/docs/api/summary.json +1 -1
- package/docs/contract-testing.md +24 -3
- package/docs/developer/GITHUB_ACTIONS_SETUP.md +8 -2
- package/docs/developer/MAINTENANCE.md +29 -3
- package/docs/developer/MIGRATION_GUIDE.md +13 -1
- package/docs/developer/NPM_AUTH_SETUP.md +13 -2
- package/docs/developer/REFACTORING.md +31 -1
- package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +18 -7
- package/docs/releases/RELEASE_NOTES_v1.1.2.md +31 -5
- package/docs/user-guides/DOCKER_SETUP.md +264 -0
- package/docs/user-guides/DTX_SETUP.md +327 -0
- package/docs/user-guides/NPM_SETUP.md +109 -0
- package/docs/user-guides/NPX_SETUP.md +281 -0
- package/docs/wordpress-rest-api-authentication-troubleshooting.md +13 -2
- package/package.json +27 -8
- package/src/cache/CacheInvalidation.ts +140 -132
- package/src/cache/CacheManager.ts +40 -29
- package/src/cache/HttpCacheWrapper.ts +105 -68
- package/src/cache/__tests__/CacheInvalidation.test.ts +123 -118
- package/src/cache/__tests__/CacheManager.test.ts +156 -152
- package/src/cache/__tests__/CachedWordPressClient.test.ts +131 -116
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +118 -115
- package/src/cache/index.ts +13 -13
- package/src/client/CachedWordPressClient.ts +90 -80
- package/src/client/api.ts +205 -205
- package/src/client/auth.ts +80 -80
- package/src/client/managers/AuthenticationManager.ts +61 -61
- package/src/client/managers/BaseManager.ts +11 -11
- package/src/client/managers/RequestManager.ts +79 -47
- package/src/client/managers/index.ts +3 -3
- package/src/config/ConfigurationSchema.ts +44 -44
- package/src/config/ServerConfiguration.ts +39 -39
- package/src/docs/DocumentationGenerator.ts +402 -295
- package/src/docs/MarkdownFormatter.ts +94 -69
- package/src/docs/index.ts +4 -4
- package/src/index.ts +24 -21
- package/src/performance/MetricsCollector.ts +90 -58
- package/src/performance/PerformanceAnalytics.ts +386 -262
- package/src/performance/PerformanceMonitor.ts +152 -118
- package/src/performance/index.ts +9 -9
- package/src/security/InputValidator.ts +148 -91
- package/src/security/SecurityConfig.ts +94 -94
- package/src/server/ConnectionTester.ts +21 -15
- package/src/server/ToolRegistry.ts +64 -51
- package/src/server.ts +2 -2
- package/src/tools/BaseToolManager.ts +6 -6
- package/src/tools/auth.ts +42 -37
- package/src/tools/cache.ts +85 -81
- package/src/tools/comments.ts +93 -91
- package/src/tools/index.ts +10 -10
- package/src/tools/media.ts +89 -89
- package/src/tools/pages.ts +89 -87
- package/src/tools/performance.ts +443 -352
- package/src/tools/posts.ts +109 -107
- package/src/tools/site.ts +86 -77
- package/src/tools/taxonomies.ts +102 -102
- package/src/tools/users.ts +77 -77
- package/src/types/client.ts +157 -60
- package/src/types/index.ts +49 -27
- package/src/types/mcp.ts +15 -15
- package/src/types/wordpress.ts +57 -29
- package/src/utils/debug.ts +37 -37
- package/src/utils/error.ts +47 -25
- package/src/utils/toolWrapper.ts +12 -8
- package/src/utils/validation.ts +116 -65
- package/dist/client/WordPressClient.d.ts +0 -81
- package/dist/client/WordPressClient.d.ts.map +0 -1
- package/dist/client/WordPressClient.js +0 -354
- package/dist/client/WordPressClient.js.map +0 -1
- package/dist/performance/AnomalyDetector.d.ts +0 -63
- package/dist/performance/AnomalyDetector.d.ts.map +0 -1
- package/dist/performance/AnomalyDetector.js +0 -222
- package/dist/performance/AnomalyDetector.js.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.d.ts +0 -67
- package/dist/performance/BenchmarkAnalyzer.d.ts.map +0 -1
- package/dist/performance/BenchmarkAnalyzer.js +0 -301
- package/dist/performance/BenchmarkAnalyzer.js.map +0 -1
- package/dist/performance/TrendAnalyzer.d.ts +0 -69
- package/dist/performance/TrendAnalyzer.d.ts.map +0 -1
- package/dist/performance/TrendAnalyzer.js +0 -203
- package/dist/performance/TrendAnalyzer.js.map +0 -1
- package/dist/tools/BaseToolClass.d.ts +0 -76
- package/dist/tools/BaseToolClass.d.ts.map +0 -1
- package/dist/tools/BaseToolClass.js +0 -104
- package/dist/tools/BaseToolClass.js.map +0 -1
- package/dist/tools/base.d.ts +0 -37
- package/dist/tools/base.d.ts.map +0 -1
- package/dist/tools/base.js +0 -60
- package/dist/tools/base.js.map +0 -1
- package/docs/user-guides/CLAUDE_DESKTOP_SETUP.md +0 -187
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* Tests for CachedWordPressClient
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { CachedWordPressClient } from
|
|
6
|
-
import type { WordPressClientConfig } from
|
|
5
|
+
import { CachedWordPressClient } from "../index.js";
|
|
6
|
+
import type { WordPressClientConfig } from "../../types/client.js";
|
|
7
7
|
|
|
8
8
|
// Mock the base WordPress client
|
|
9
|
-
jest.mock(
|
|
9
|
+
jest.mock("../../client/api.js", () => {
|
|
10
10
|
return {
|
|
11
11
|
WordPressClient: jest.fn().mockImplementation(() => ({
|
|
12
|
-
baseUrl:
|
|
13
|
-
auth: { method:
|
|
12
|
+
baseUrl: "https://example.com",
|
|
13
|
+
auth: { method: "app-password", username: "test", appPassword: "test" },
|
|
14
14
|
jwtToken: null,
|
|
15
15
|
request: jest.fn(),
|
|
16
16
|
getPosts: jest.fn(),
|
|
@@ -21,26 +21,26 @@ jest.mock('../../client/api.js', () => {
|
|
|
21
21
|
getCurrentUser: jest.fn(),
|
|
22
22
|
getCategories: jest.fn(),
|
|
23
23
|
getTags: jest.fn(),
|
|
24
|
-
getSiteSettings: jest.fn()
|
|
25
|
-
}))
|
|
24
|
+
getSiteSettings: jest.fn(),
|
|
25
|
+
})),
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
describe(
|
|
29
|
+
describe("CachedWordPressClient", () => {
|
|
30
30
|
let client: CachedWordPressClient;
|
|
31
31
|
let config: WordPressClientConfig;
|
|
32
32
|
|
|
33
33
|
beforeEach(() => {
|
|
34
34
|
config = {
|
|
35
|
-
baseUrl:
|
|
35
|
+
baseUrl: "https://example.com",
|
|
36
36
|
auth: {
|
|
37
|
-
method:
|
|
38
|
-
username:
|
|
39
|
-
appPassword:
|
|
40
|
-
}
|
|
37
|
+
method: "app-password",
|
|
38
|
+
username: "test",
|
|
39
|
+
appPassword: "test-password",
|
|
40
|
+
},
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
client = new CachedWordPressClient(config,
|
|
43
|
+
client = new CachedWordPressClient(config, "test-site");
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
afterEach(() => {
|
|
@@ -48,29 +48,30 @@ describe('CachedWordPressClient', () => {
|
|
|
48
48
|
jest.clearAllMocks();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
describe(
|
|
52
|
-
test(
|
|
51
|
+
describe("Initialization", () => {
|
|
52
|
+
test("should initialize with caching system", () => {
|
|
53
53
|
expect(client).toBeDefined();
|
|
54
|
-
expect(client[
|
|
55
|
-
expect(client[
|
|
56
|
-
expect(client[
|
|
54
|
+
expect(client["cacheManager"]).toBeDefined();
|
|
55
|
+
expect(client["httpCache"]).toBeDefined();
|
|
56
|
+
expect(client["cacheInvalidation"]).toBeDefined();
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
test(
|
|
60
|
-
const customClient = new CachedWordPressClient(config,
|
|
61
|
-
expect(customClient[
|
|
59
|
+
test("should use provided site ID", () => {
|
|
60
|
+
const customClient = new CachedWordPressClient(config, "custom-site");
|
|
61
|
+
expect(customClient["siteId"]).toBe("custom-site");
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
test(
|
|
64
|
+
test("should default to \"default\" site ID", () => {
|
|
65
65
|
const defaultClient = new CachedWordPressClient(config);
|
|
66
|
-
expect(defaultClient[
|
|
66
|
+
expect(defaultClient["siteId"]).toBe("default");
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
describe(
|
|
71
|
-
test(
|
|
72
|
-
const mockResponse = [{ id: 1, title:
|
|
73
|
-
(client as any).request = jest
|
|
70
|
+
describe("GET Request Caching", () => {
|
|
71
|
+
test("should cache GET requests", async () => {
|
|
72
|
+
const mockResponse = [{ id: 1, title: "Test Post" }];
|
|
73
|
+
(client as any).request = jest
|
|
74
|
+
.fn()
|
|
74
75
|
.mockImplementationOnce(async () => mockResponse)
|
|
75
76
|
.mockImplementationOnce(async () => mockResponse);
|
|
76
77
|
|
|
@@ -86,8 +87,8 @@ describe('CachedWordPressClient', () => {
|
|
|
86
87
|
expect((client as any).request).toHaveBeenCalledTimes(1);
|
|
87
88
|
});
|
|
88
89
|
|
|
89
|
-
test(
|
|
90
|
-
const mockPost = { id: 1, title:
|
|
90
|
+
test("should cache individual post requests", async () => {
|
|
91
|
+
const mockPost = { id: 1, title: "Test Post" };
|
|
91
92
|
(client as any).request = jest.fn().mockResolvedValue(mockPost);
|
|
92
93
|
|
|
93
94
|
const result1 = await client.getPost(1);
|
|
@@ -99,117 +100,123 @@ describe('CachedWordPressClient', () => {
|
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
102
|
|
|
102
|
-
describe(
|
|
103
|
-
test(
|
|
104
|
-
const mockPost = { id: 1, title:
|
|
105
|
-
const mockCreateData = { title:
|
|
106
|
-
|
|
103
|
+
describe("Write Operations and Cache Invalidation", () => {
|
|
104
|
+
test("should invalidate cache on post creation", async () => {
|
|
105
|
+
const mockPost = { id: 1, title: "New Post" };
|
|
106
|
+
const mockCreateData = { title: "New Post", content: "Content" };
|
|
107
|
+
|
|
107
108
|
// Mock the parent class methods
|
|
108
109
|
const _originalCreatePost = client.createPost;
|
|
109
110
|
client.createPost = jest.fn().mockResolvedValue(mockPost);
|
|
110
|
-
|
|
111
|
-
const invalidateSpy = jest.spyOn(
|
|
111
|
+
|
|
112
|
+
const invalidateSpy = jest.spyOn(
|
|
113
|
+
client["cacheInvalidation"],
|
|
114
|
+
"invalidateResource",
|
|
115
|
+
);
|
|
112
116
|
|
|
113
117
|
await client.createPost(mockCreateData);
|
|
114
118
|
|
|
115
|
-
expect(invalidateSpy).toHaveBeenCalledWith(
|
|
119
|
+
expect(invalidateSpy).toHaveBeenCalledWith("posts", 1, "create");
|
|
116
120
|
});
|
|
117
121
|
|
|
118
|
-
test(
|
|
119
|
-
const mockPost = { id: 1, title:
|
|
120
|
-
const mockUpdateData = { id: 1, title:
|
|
121
|
-
|
|
122
|
+
test("should invalidate cache on post update", async () => {
|
|
123
|
+
const mockPost = { id: 1, title: "Updated Post" };
|
|
124
|
+
const mockUpdateData = { id: 1, title: "Updated Post" };
|
|
125
|
+
|
|
122
126
|
client.updatePost = jest.fn().mockResolvedValue(mockPost);
|
|
123
|
-
const invalidateSpy = jest.spyOn(
|
|
127
|
+
const invalidateSpy = jest.spyOn(
|
|
128
|
+
client["cacheInvalidation"],
|
|
129
|
+
"invalidateResource",
|
|
130
|
+
);
|
|
124
131
|
|
|
125
132
|
await client.updatePost(mockUpdateData);
|
|
126
133
|
|
|
127
|
-
expect(invalidateSpy).toHaveBeenCalledWith(
|
|
134
|
+
expect(invalidateSpy).toHaveBeenCalledWith("posts", 1, "update");
|
|
128
135
|
});
|
|
129
136
|
|
|
130
|
-
test(
|
|
137
|
+
test("should invalidate cache on post deletion", async () => {
|
|
131
138
|
client.deletePost = jest.fn().mockResolvedValue(undefined);
|
|
132
|
-
const invalidateSpy = jest.spyOn(
|
|
139
|
+
const invalidateSpy = jest.spyOn(
|
|
140
|
+
client["cacheInvalidation"],
|
|
141
|
+
"invalidateResource",
|
|
142
|
+
);
|
|
133
143
|
|
|
134
144
|
await client.deletePost(1);
|
|
135
145
|
|
|
136
|
-
expect(invalidateSpy).toHaveBeenCalledWith(
|
|
146
|
+
expect(invalidateSpy).toHaveBeenCalledWith("posts", 1, "delete");
|
|
137
147
|
});
|
|
138
148
|
});
|
|
139
149
|
|
|
140
|
-
describe(
|
|
141
|
-
test(
|
|
142
|
-
const mockSettings = { title:
|
|
150
|
+
describe("Cache Configuration by Endpoint Type", () => {
|
|
151
|
+
test("should use static caching for site settings", async () => {
|
|
152
|
+
const mockSettings = { title: "Test Site" };
|
|
143
153
|
(client as any).request = jest.fn().mockResolvedValue(mockSettings);
|
|
144
154
|
|
|
145
155
|
await client.getSiteSettings();
|
|
146
156
|
|
|
147
157
|
// Verify request was made with static cache configuration
|
|
148
|
-
expect((client as any).request).toHaveBeenCalledWith(
|
|
149
|
-
'GET',
|
|
150
|
-
'settings'
|
|
151
|
-
);
|
|
158
|
+
expect((client as any).request).toHaveBeenCalledWith("GET", "settings");
|
|
152
159
|
});
|
|
153
160
|
|
|
154
|
-
test(
|
|
155
|
-
const mockCategories = [{ id: 1, name:
|
|
161
|
+
test("should use semi-static caching for categories", async () => {
|
|
162
|
+
const mockCategories = [{ id: 1, name: "Test Category" }];
|
|
156
163
|
(client as any).request = jest.fn().mockResolvedValue(mockCategories);
|
|
157
164
|
|
|
158
165
|
await client.getCategories();
|
|
159
166
|
|
|
160
167
|
expect((client as any).request).toHaveBeenCalledWith(
|
|
161
|
-
|
|
162
|
-
|
|
168
|
+
"GET",
|
|
169
|
+
"categories",
|
|
163
170
|
null,
|
|
164
|
-
{ params: {} }
|
|
171
|
+
{ params: {} },
|
|
165
172
|
);
|
|
166
173
|
});
|
|
167
174
|
|
|
168
|
-
test(
|
|
169
|
-
const mockUser = { id: 1, username:
|
|
175
|
+
test("should use session caching for current user", async () => {
|
|
176
|
+
const mockUser = { id: 1, username: "testuser" };
|
|
170
177
|
(client as any).request = jest.fn().mockResolvedValue(mockUser);
|
|
171
178
|
|
|
172
179
|
await client.getCurrentUser();
|
|
173
180
|
|
|
174
|
-
expect((client as any).request).toHaveBeenCalledWith(
|
|
175
|
-
'GET',
|
|
176
|
-
'users/me'
|
|
177
|
-
);
|
|
181
|
+
expect((client as any).request).toHaveBeenCalledWith("GET", "users/me");
|
|
178
182
|
});
|
|
179
183
|
});
|
|
180
184
|
|
|
181
|
-
describe(
|
|
182
|
-
test(
|
|
183
|
-
const clearSpy = jest.spyOn(client[
|
|
184
|
-
|
|
185
|
+
describe("Cache Management", () => {
|
|
186
|
+
test("should clear all cache", () => {
|
|
187
|
+
const clearSpy = jest.spyOn(client["httpCache"], "invalidateAll");
|
|
188
|
+
|
|
185
189
|
const result = client.clearCache();
|
|
186
|
-
|
|
190
|
+
|
|
187
191
|
expect(clearSpy).toHaveBeenCalled();
|
|
188
|
-
expect(typeof result).toBe(
|
|
192
|
+
expect(typeof result).toBe("number");
|
|
189
193
|
});
|
|
190
194
|
|
|
191
|
-
test(
|
|
192
|
-
const pattern =
|
|
193
|
-
const clearPatternSpy = jest.spyOn(
|
|
194
|
-
|
|
195
|
+
test("should clear cache by pattern", () => {
|
|
196
|
+
const pattern = "posts.*";
|
|
197
|
+
const clearPatternSpy = jest.spyOn(
|
|
198
|
+
client["httpCache"],
|
|
199
|
+
"invalidatePattern",
|
|
200
|
+
);
|
|
201
|
+
|
|
195
202
|
const result = client.clearCachePattern(pattern);
|
|
196
|
-
|
|
203
|
+
|
|
197
204
|
expect(clearPatternSpy).toHaveBeenCalledWith(pattern);
|
|
198
|
-
expect(typeof result).toBe(
|
|
205
|
+
expect(typeof result).toBe("number");
|
|
199
206
|
});
|
|
200
207
|
|
|
201
|
-
test(
|
|
208
|
+
test("should provide cache statistics", () => {
|
|
202
209
|
const stats = client.getCacheStats();
|
|
203
|
-
|
|
204
|
-
expect(stats).toHaveProperty(
|
|
205
|
-
expect(stats).toHaveProperty(
|
|
206
|
-
expect(stats.cache).toHaveProperty(
|
|
207
|
-
expect(stats.cache).toHaveProperty(
|
|
208
|
-
expect(stats.cache).toHaveProperty(
|
|
209
|
-
expect(stats.invalidation).toHaveProperty(
|
|
210
|
+
|
|
211
|
+
expect(stats).toHaveProperty("cache");
|
|
212
|
+
expect(stats).toHaveProperty("invalidation");
|
|
213
|
+
expect(stats.cache).toHaveProperty("hits");
|
|
214
|
+
expect(stats.cache).toHaveProperty("misses");
|
|
215
|
+
expect(stats.cache).toHaveProperty("totalSize");
|
|
216
|
+
expect(stats.invalidation).toHaveProperty("queueSize");
|
|
210
217
|
});
|
|
211
218
|
|
|
212
|
-
test(
|
|
219
|
+
test("should warm cache with essential data", async () => {
|
|
213
220
|
// Mock all the methods that warmCache calls
|
|
214
221
|
client.getCurrentUser = jest.fn().mockResolvedValue({ id: 1 });
|
|
215
222
|
client.getCategories = jest.fn().mockResolvedValue([]);
|
|
@@ -224,23 +231,25 @@ describe('CachedWordPressClient', () => {
|
|
|
224
231
|
expect(client.getSiteSettings).toHaveBeenCalled();
|
|
225
232
|
});
|
|
226
233
|
|
|
227
|
-
test(
|
|
228
|
-
client.getCurrentUser = jest
|
|
234
|
+
test("should handle cache warming errors gracefully", async () => {
|
|
235
|
+
client.getCurrentUser = jest
|
|
236
|
+
.fn()
|
|
237
|
+
.mockRejectedValue(new Error("Auth failed"));
|
|
229
238
|
client.getCategories = jest.fn().mockResolvedValue([]);
|
|
230
239
|
client.getTags = jest.fn().mockResolvedValue([]);
|
|
231
240
|
client.getSiteSettings = jest.fn().mockResolvedValue({});
|
|
232
241
|
|
|
233
242
|
// Should not throw despite getCurrentUser failing
|
|
234
243
|
await expect(client.warmCache()).resolves.toBeUndefined();
|
|
235
|
-
|
|
244
|
+
|
|
236
245
|
expect(client.getCategories).toHaveBeenCalled();
|
|
237
246
|
expect(client.getTags).toHaveBeenCalled();
|
|
238
247
|
expect(client.getSiteSettings).toHaveBeenCalled();
|
|
239
248
|
});
|
|
240
249
|
});
|
|
241
250
|
|
|
242
|
-
describe(
|
|
243
|
-
test(
|
|
251
|
+
describe("Cache Key Generation", () => {
|
|
252
|
+
test("should generate different cache keys for different parameters", async () => {
|
|
244
253
|
const mockPosts = [{ id: 1 }];
|
|
245
254
|
(client as any).request = jest.fn().mockResolvedValue(mockPosts);
|
|
246
255
|
|
|
@@ -252,12 +261,12 @@ describe('CachedWordPressClient', () => {
|
|
|
252
261
|
expect((client as any).request).toHaveBeenCalledTimes(2);
|
|
253
262
|
});
|
|
254
263
|
|
|
255
|
-
test(
|
|
264
|
+
test("should use same cache key for identical parameters", async () => {
|
|
256
265
|
const mockPosts = [{ id: 1 }];
|
|
257
266
|
(client as any).request = jest.fn().mockResolvedValue(mockPosts);
|
|
258
267
|
|
|
259
|
-
const params = { per_page: 10, status: [
|
|
260
|
-
|
|
268
|
+
const params = { per_page: 10, status: ["publish"] as ["publish"] };
|
|
269
|
+
|
|
261
270
|
await client.getPosts(params);
|
|
262
271
|
await client.getPosts(params);
|
|
263
272
|
|
|
@@ -266,39 +275,45 @@ describe('CachedWordPressClient', () => {
|
|
|
266
275
|
});
|
|
267
276
|
});
|
|
268
277
|
|
|
269
|
-
describe(
|
|
270
|
-
test(
|
|
271
|
-
const resource1 = (client as any).extractResourceFromEndpoint(
|
|
272
|
-
const resource2 = (client as any).extractResourceFromEndpoint(
|
|
273
|
-
|
|
278
|
+
describe("Helper Methods", () => {
|
|
279
|
+
test("should extract resource from endpoint", () => {
|
|
280
|
+
const resource1 = (client as any).extractResourceFromEndpoint("posts");
|
|
281
|
+
const resource2 = (client as any).extractResourceFromEndpoint(
|
|
282
|
+
"posts/123",
|
|
283
|
+
);
|
|
284
|
+
const resource3 = (client as any).extractResourceFromEndpoint(
|
|
285
|
+
"categories",
|
|
286
|
+
);
|
|
274
287
|
|
|
275
|
-
expect(resource1).toBe(
|
|
276
|
-
expect(resource2).toBe(
|
|
277
|
-
expect(resource3).toBe(
|
|
288
|
+
expect(resource1).toBe("posts");
|
|
289
|
+
expect(resource2).toBe("posts");
|
|
290
|
+
expect(resource3).toBe("categories");
|
|
278
291
|
});
|
|
279
292
|
|
|
280
|
-
test(
|
|
281
|
-
const id1 = (client as any).extractIdFromEndpoint(
|
|
282
|
-
const id2 = (client as any).extractIdFromEndpoint(
|
|
283
|
-
const id3 = (client as any).extractIdFromEndpoint(
|
|
293
|
+
test("should extract ID from endpoint", () => {
|
|
294
|
+
const id1 = (client as any).extractIdFromEndpoint("posts/123");
|
|
295
|
+
const id2 = (client as any).extractIdFromEndpoint("posts/123/revisions");
|
|
296
|
+
const id3 = (client as any).extractIdFromEndpoint("posts");
|
|
284
297
|
|
|
285
298
|
expect(id1).toBe(123);
|
|
286
299
|
expect(id2).toBe(123);
|
|
287
300
|
expect(id3).toBeUndefined();
|
|
288
301
|
});
|
|
289
302
|
|
|
290
|
-
test(
|
|
291
|
-
expect((client as any).isStaticEndpoint(
|
|
292
|
-
expect((client as any).isStaticEndpoint(
|
|
293
|
-
expect((client as any).isStaticEndpoint(
|
|
303
|
+
test("should identify endpoint types correctly", () => {
|
|
304
|
+
expect((client as any).isStaticEndpoint("settings")).toBe(true);
|
|
305
|
+
expect((client as any).isStaticEndpoint("types")).toBe(true);
|
|
306
|
+
expect((client as any).isStaticEndpoint("posts")).toBe(false);
|
|
294
307
|
|
|
295
|
-
expect((client as any).isSemiStaticEndpoint(
|
|
296
|
-
expect((client as any).isSemiStaticEndpoint(
|
|
297
|
-
expect((client as any).isSemiStaticEndpoint(
|
|
308
|
+
expect((client as any).isSemiStaticEndpoint("categories")).toBe(true);
|
|
309
|
+
expect((client as any).isSemiStaticEndpoint("tags")).toBe(true);
|
|
310
|
+
expect((client as any).isSemiStaticEndpoint("posts")).toBe(false);
|
|
298
311
|
|
|
299
|
-
expect((client as any).isSessionEndpoint(
|
|
300
|
-
expect((client as any).isSessionEndpoint(
|
|
301
|
-
|
|
312
|
+
expect((client as any).isSessionEndpoint("users/me")).toBe(true);
|
|
313
|
+
expect((client as any).isSessionEndpoint("application-passwords")).toBe(
|
|
314
|
+
true,
|
|
315
|
+
);
|
|
316
|
+
expect((client as any).isSessionEndpoint("posts")).toBe(false);
|
|
302
317
|
});
|
|
303
318
|
});
|
|
304
319
|
});
|