Skip to content

Commit 732f927

Browse files
committed
fix tests, add new basic-usage test
1 parent 952903e commit 732f927

File tree

6 files changed

+120
-6
lines changed

6 files changed

+120
-6
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ test-results/
1616
# WordPress
1717
.wp-env
1818
.wp-env.override.json
19-
wp-env/
2019
uploads/
2120
debug.log
2221
__MACOSX

plugins/wpgraphql-logging/.wp-env.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"tests": {
88
"plugins": [
99
"https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip",
10+
"https://github.com/johnbillion/wp-crontrol/archive/refs/tags/1.19.3.zip",
1011
".",
1112
"./tests/e2e/plugins/reset-wpgraphql-logging-settings/"
1213
]

plugins/wpgraphql-logging/tests/e2e/config/global-setup.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ async function globalSetup(config) {
1717
// Authenticate and save the storageState to disk.
1818
await requestUtils.setupRest();
1919

20-
await Promise.all([
21-
requestUtils.deleteAllPosts(),
22-
requestUtils.deleteAllPages(),
23-
requestUtils.resetPreferences(),
24-
]);
20+
await Promise.all([requestUtils.resetPreferences()]);
2521

2622
await requestContext.dispose();
2723
}

plugins/wpgraphql-logging/tests/e2e/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const PLUGIN_SLUG = "wpgraphql-logging";
22
export const RESET_HELPER_PLUGIN_SLUG = "reset-wpgraphql-logging-settings";
3+
34
export const GET_POSTS_QUERY = `
45
query GetPosts {
56
posts(first: 5) {

plugins/wpgraphql-logging/tests/e2e/specs/basic-usage.spec.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,100 @@ test.describe("Configure WPGraphQL Logging Plugin and Verify Logging Works", ()
9797
page.locator('td.colspanchange:has-text("No items found.")')
9898
).toBeVisible();
9999
});
100+
101+
test("should download the log as CSV and verify the content", async ({
102+
page,
103+
admin,
104+
request,
105+
}) => {
106+
// Set up logging settings
107+
await goToLoggingSettingsPage(admin);
108+
await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
109+
110+
await configureLogging(page, {
111+
enabled: true,
112+
dataSampling: "100",
113+
eventLogSelection: ["graphql_request_results"],
114+
});
115+
116+
await expect(page.locator(".notice.notice-success")).toBeVisible();
117+
118+
// Execute a GraphQL query
119+
const response = await executeGraphQLQuery(request, GET_POSTS_QUERY);
120+
expect(response.ok()).toBeTruthy();
121+
122+
// Check that the log appears in the logs list
123+
await goToLogsListPage(admin);
124+
await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
125+
126+
const logRow = page
127+
.locator("#the-list tr")
128+
.filter({ hasText: "GetPosts" })
129+
.first();
130+
await expect(logRow).toBeVisible({ timeout: 10000 });
131+
132+
// View log details
133+
const downloadButton = logRow.locator(".row-actions .download a");
134+
await expect(downloadButton).toBeVisible();
135+
136+
const downloadPromise = page.waitForEvent("download");
137+
await downloadButton.focus();
138+
await downloadButton.click();
139+
const download = await downloadPromise;
140+
141+
// Verify download properties
142+
expect(download.suggestedFilename()).toMatch(/graphql_log_\d+\.csv/);
143+
expect(download.suggestedFilename()).toContain(".csv");
144+
145+
// Optionally save and verify the content
146+
const path = await download.path();
147+
const fs = require("fs");
148+
const content = fs.readFileSync(path, "utf8");
149+
150+
// Verify CSV contains expected data
151+
expect(content).toContain("ID");
152+
expect(content).toContain("Date");
153+
expect(content).toContain("Level");
154+
expect(content).toContain("Message");
155+
expect(content).toContain("GetPosts");
156+
});
157+
158+
// test("should set data sampling to 10% and verify only 1 log is created", async ({
159+
// page,
160+
// admin,
161+
// request,
162+
// }) => {
163+
// // Set up logging settings
164+
// await goToLoggingSettingsPage(admin);
165+
// await expect(page.locator("h1")).toHaveText("WPGraphQL Logging Settings");
166+
167+
// await configureLogging(page, {
168+
// enabled: true,
169+
// dataSampling: "50",
170+
// eventLogSelection: ["graphql_request_results"],
171+
// });
172+
173+
// await expect(page.locator(".notice.notice-success")).toBeVisible();
174+
175+
// // Execute a GraphQL queries
176+
// const responses = await Promise.all(
177+
// Array.from({ length: 10 }, async () =>
178+
// executeGraphQLQuery(request, GET_POSTS_QUERY)
179+
// )
180+
// );
181+
// await Promise.all(
182+
// responses.map(async (response) => {
183+
// return expect(response.ok()).toBeTruthy();
184+
// })
185+
// );
186+
187+
// // Navigate to logs and verify no new logs were created
188+
// await goToLogsListPage(admin);
189+
// await expect(page.locator("h1")).toContainText("WPGraphQL Logs");
190+
191+
// const logRow = page.locator("#the-list tr").filter({ hasText: "GetPosts" });
192+
193+
// const logCount = await logRow.count();
194+
// expect(logCount).toBeLessThanOrEqual(5);
195+
// });
100196
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<IfModule mod_headers.c>
2+
Header set Access-Control-Allow-Origin "*"
3+
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
4+
Header set Access-Control-Allow-Headers "Authorization, Content-Type"
5+
</IfModule>
6+
7+
# BEGIN WordPress
8+
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
9+
# dynamically generated, and should only be modified via WordPress filters.
10+
# Any changes to the directives between these markers will be overwritten.
11+
<IfModule mod_rewrite.c>
12+
RewriteEngine On
13+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
14+
RewriteBase /
15+
RewriteRule ^index\.php$ - [L]
16+
RewriteCond %{REQUEST_FILENAME} !-f
17+
RewriteCond %{REQUEST_FILENAME} !-d
18+
RewriteRule . /index.php [L]
19+
</IfModule>
20+
21+
# END WordPress

0 commit comments

Comments
 (0)