u
This commit is contained in:
94
scripts/test-mcp.js
Normal file
94
scripts/test-mcp.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import assert from 'node:assert';
|
||||
import LibDashStore from '../src/index.js';
|
||||
import { BetterSqlite3Provider } from '../src/providers/sqlite3/index.js';
|
||||
|
||||
async function main() {
|
||||
console.log('Testing MCP store methods on in-memory SQLite...');
|
||||
const provider = new BetterSqlite3Provider({ path: ':memory:' });
|
||||
await provider.initialize();
|
||||
const store = await new LibDashStore(provider);
|
||||
|
||||
// 1. Create a google_auth user
|
||||
const googleAuthId = await store.google_auth.add('mcp-tester@example.com');
|
||||
assert(googleAuthId > 0, 'googleAuthId should be positive integer');
|
||||
|
||||
// 2. Register client
|
||||
const client = await store.mcp.registerClient({
|
||||
clientId: 'test-client-123',
|
||||
clientSecret: 'secret-456',
|
||||
clientName: 'Test Client',
|
||||
redirectUris: ['http://localhost:3000/callback'],
|
||||
grantTypes: ['authorization_code', 'refresh_token'],
|
||||
responseTypes: ['code'],
|
||||
scope: 'mcp:tools',
|
||||
});
|
||||
console.log('Registered client:', client);
|
||||
assert.strictEqual(client.clientId, 'test-client-123');
|
||||
assert.strictEqual(client.clientName, 'Test Client');
|
||||
|
||||
// 3. Get client
|
||||
const fetched = await store.mcp.getClient('test-client-123');
|
||||
assert(fetched, 'Should find client');
|
||||
assert.strictEqual(fetched.clientId, 'test-client-123');
|
||||
|
||||
// 4. List clients
|
||||
const clients = await store.mcp.listClients();
|
||||
assert.strictEqual(clients.length, 1);
|
||||
|
||||
// 5. Create auth code
|
||||
const code = 'auth-code-xyz';
|
||||
await store.mcp.createAuthCode({
|
||||
code,
|
||||
clientId: 'test-client-123',
|
||||
googleAuthId,
|
||||
redirectUri: 'http://localhost:3000/callback',
|
||||
codeChallenge: 'E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM',
|
||||
codeChallengeMethod: 'S256',
|
||||
scope: 'mcp:tools',
|
||||
expiresAt: new Date(Date.now() + 300_000),
|
||||
});
|
||||
|
||||
// 6. Get auth code
|
||||
const codeRow = await store.mcp.getAuthCode(code);
|
||||
assert(codeRow, 'Should find auth code');
|
||||
assert.strictEqual(codeRow.clientId, 'test-client-123');
|
||||
assert.strictEqual(codeRow.used, 0);
|
||||
|
||||
// 7. Consume auth code
|
||||
await store.mcp.consumeAuthCode(code);
|
||||
const consumedRow = await store.mcp.getAuthCode(code);
|
||||
assert.strictEqual(consumedRow.used, 1);
|
||||
|
||||
// 8. Create refresh token
|
||||
const refreshToken = 'refresh-token-abc';
|
||||
await store.mcp.createRefreshToken({
|
||||
refreshToken,
|
||||
clientId: 'test-client-123',
|
||||
googleAuthId,
|
||||
scope: 'mcp:tools',
|
||||
expiresAt: new Date(Date.now() + 86400_000),
|
||||
});
|
||||
|
||||
// 9. Get refresh token
|
||||
const tokenRow = await store.mcp.getRefreshToken(refreshToken);
|
||||
assert(tokenRow, 'Should find refresh token');
|
||||
assert.strictEqual(tokenRow.revoked, 0);
|
||||
|
||||
// 10. Revoke refresh token
|
||||
await store.mcp.revokeRefreshToken(refreshToken);
|
||||
const revokedRow = await store.mcp.getRefreshToken(refreshToken);
|
||||
assert.strictEqual(revokedRow.revoked, 1);
|
||||
|
||||
// 11. Delete client
|
||||
await store.mcp.deleteClient('test-client-123');
|
||||
const deleted = await store.mcp.getClient('test-client-123');
|
||||
assert.strictEqual(deleted, null);
|
||||
|
||||
await provider.close();
|
||||
console.log('✓ All MCP store tests passed successfully!');
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('Test failed:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -214,6 +214,18 @@ async function run() {
|
||||
assert.equal(shipmentsAfterDel.length, 1);
|
||||
console.log('PASS: Unshipped shipment 2 successfully deleted');
|
||||
|
||||
// 9. Verify peek next number works for entity and other types without error
|
||||
const nextEntity = await store.entity.peekNextNumber(googleAuthId);
|
||||
assert.ok(typeof nextEntity === 'string' && nextEntity.length > 0);
|
||||
console.log('PASS: store.entity.peekNextNumber succeeded:', nextEntity);
|
||||
|
||||
const numList = await store.numbers.list(googleAuthId);
|
||||
assert.ok(Array.isArray(numList) && numList.length > 0);
|
||||
const shipmentSeq = numList.find((n) => n.type === 'shipment');
|
||||
assert.ok(shipmentSeq, 'Expected shipment sequence in numbers.list');
|
||||
assert.equal(shipmentSeq.prefix, '-L-');
|
||||
console.log('PASS: store.numbers.list includes shipment with prefix -L-');
|
||||
|
||||
console.log('--- ALL TESTS PASSED SUCCESSFULLY! ---');
|
||||
} finally {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user