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); });