mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-03-28 13:13:08 +00:00
fix: update saveNode test mocks for docs preservation pattern
Tests now account for the SELECT query that reads existing docs before INSERT OR REPLACE, and the 3 extra params (npm_readme, ai_documentation_summary, ai_summary_generated_at). Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -119,8 +119,13 @@ class MockPreparedStatement implements PreparedStatement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// saveNode - SELECT existing doc fields before upsert
|
||||||
|
if (this.sql.includes('SELECT npm_readme, ai_documentation_summary, ai_summary_generated_at FROM nodes')) {
|
||||||
|
this.get = vi.fn(() => undefined); // No existing row by default
|
||||||
|
}
|
||||||
|
|
||||||
// saveNode - INSERT OR REPLACE
|
// saveNode - INSERT OR REPLACE
|
||||||
if (this.sql.includes('INSERT INTO nodes')) {
|
if (this.sql.includes('INSERT OR REPLACE INTO nodes')) {
|
||||||
this.run = vi.fn((...params: any[]): RunResult => {
|
this.run = vi.fn((...params: any[]): RunResult => {
|
||||||
const nodes = this.mockData.get('community_nodes') || [];
|
const nodes = this.mockData.get('community_nodes') || [];
|
||||||
const nodeType = params[0];
|
const nodeType = params[0];
|
||||||
|
|||||||
@@ -49,7 +49,12 @@ class MockPreparedStatement implements PreparedStatement {
|
|||||||
if (sql.includes('SELECT * FROM nodes WHERE node_type = ?')) {
|
if (sql.includes('SELECT * FROM nodes WHERE node_type = ?')) {
|
||||||
this.get = vi.fn((nodeType: string) => this.mockData.get(`node:${nodeType}`));
|
this.get = vi.fn((nodeType: string) => this.mockData.get(`node:${nodeType}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure get() for saveNode's SELECT to preserve existing doc fields
|
||||||
|
if (sql.includes('SELECT npm_readme, ai_documentation_summary, ai_summary_generated_at FROM nodes')) {
|
||||||
|
this.get = vi.fn(() => undefined); // No existing row by default
|
||||||
|
}
|
||||||
|
|
||||||
// Configure all() for getAITools
|
// Configure all() for getAITools
|
||||||
if (sql.includes('WHERE is_ai_tool = 1')) {
|
if (sql.includes('WHERE is_ai_tool = 1')) {
|
||||||
this.all = vi.fn(() => this.mockData.get('ai_tools') || []);
|
this.all = vi.fn(() => this.mockData.get('ai_tools') || []);
|
||||||
@@ -91,7 +96,7 @@ describe('NodeRepository - Core Functionality', () => {
|
|||||||
repository.saveNode(parsedNode);
|
repository.saveNode(parsedNode);
|
||||||
|
|
||||||
// Verify prepare was called with correct SQL
|
// Verify prepare was called with correct SQL
|
||||||
expect(mockAdapter.prepare).toHaveBeenCalledWith(expect.stringContaining('INSERT INTO nodes'));
|
expect(mockAdapter.prepare).toHaveBeenCalledWith(expect.stringContaining('INSERT OR REPLACE INTO nodes'));
|
||||||
|
|
||||||
// Get the prepared statement and verify run was called
|
// Get the prepared statement and verify run was called
|
||||||
const stmt = mockAdapter._getStatement(mockAdapter.prepare.mock.lastCall?.[0] || '');
|
const stmt = mockAdapter._getStatement(mockAdapter.prepare.mock.lastCall?.[0] || '');
|
||||||
@@ -123,7 +128,10 @@ describe('NodeRepository - Core Functionality', () => {
|
|||||||
null, // npmPackageName
|
null, // npmPackageName
|
||||||
null, // npmVersion
|
null, // npmVersion
|
||||||
0, // npmDownloads
|
0, // npmDownloads
|
||||||
null // communityFetchedAt
|
null, // communityFetchedAt
|
||||||
|
null, // npm_readme (preserved from existing)
|
||||||
|
null, // ai_documentation_summary (preserved from existing)
|
||||||
|
null // ai_summary_generated_at (preserved from existing)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,21 @@ describe('NodeRepository - Outputs Handling', () => {
|
|||||||
all: vi.fn()
|
all: vi.fn()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// saveNode now calls prepare twice: first a SELECT (returns get), then INSERT (returns run).
|
||||||
|
// We create a separate mock for the SELECT statement that returns undefined (no existing row).
|
||||||
|
const selectStatement = {
|
||||||
|
run: vi.fn(),
|
||||||
|
get: vi.fn().mockReturnValue(undefined),
|
||||||
|
all: vi.fn()
|
||||||
|
};
|
||||||
|
|
||||||
mockDb = {
|
mockDb = {
|
||||||
prepare: vi.fn().mockReturnValue(mockStatement),
|
prepare: vi.fn((sql: string) => {
|
||||||
|
if (sql.includes('SELECT npm_readme')) {
|
||||||
|
return selectStatement;
|
||||||
|
}
|
||||||
|
return mockStatement;
|
||||||
|
}),
|
||||||
transaction: vi.fn(),
|
transaction: vi.fn(),
|
||||||
exec: vi.fn(),
|
exec: vi.fn(),
|
||||||
close: vi.fn(),
|
close: vi.fn(),
|
||||||
@@ -56,7 +69,7 @@ describe('NodeRepository - Outputs Handling', () => {
|
|||||||
repository.saveNode(node);
|
repository.saveNode(node);
|
||||||
|
|
||||||
expect(mockDb.prepare).toHaveBeenCalledWith(
|
expect(mockDb.prepare).toHaveBeenCalledWith(
|
||||||
expect.stringContaining('INSERT INTO nodes')
|
expect.stringContaining('INSERT OR REPLACE INTO nodes')
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(mockStatement.run).toHaveBeenCalledWith(
|
expect(mockStatement.run).toHaveBeenCalledWith(
|
||||||
@@ -87,7 +100,10 @@ describe('NodeRepository - Outputs Handling', () => {
|
|||||||
null, // npm_package_name
|
null, // npm_package_name
|
||||||
null, // npm_version
|
null, // npm_version
|
||||||
0, // npm_downloads
|
0, // npm_downloads
|
||||||
null // community_fetched_at
|
null, // community_fetched_at
|
||||||
|
null, // npm_readme (preserved from existing)
|
||||||
|
null, // ai_documentation_summary (preserved from existing)
|
||||||
|
null // ai_summary_generated_at (preserved from existing)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user