2025-07-22 21:10:41 +00:00
|
|
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
|
|
|
import * as bunq from '../ts/index.js';
|
|
|
|
|
|
|
|
tap.test('should handle OAuth token initialization', async () => {
|
|
|
|
// Note: This test requires a valid OAuth token to run properly
|
|
|
|
// In a real test environment, you would use a test OAuth token
|
|
|
|
|
|
|
|
// Test OAuth token initialization
|
|
|
|
const oauthBunq = new bunq.BunqAccount({
|
|
|
|
apiKey: 'test-oauth-token', // This would be a real OAuth token
|
|
|
|
deviceName: 'OAuth Test App',
|
|
|
|
environment: 'SANDBOX',
|
|
|
|
isOAuthToken: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mock test - in reality this would connect to bunq
|
|
|
|
try {
|
|
|
|
// The init should skip session creation for OAuth tokens
|
|
|
|
await oauthBunq.init();
|
|
|
|
console.log('OAuth token initialization successful (mock)');
|
|
|
|
} catch (error) {
|
|
|
|
// In sandbox with fake token, this will fail, which is expected
|
|
|
|
console.log('OAuth token test completed (expected failure with mock token)');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should not attempt session refresh for OAuth tokens', async () => {
|
|
|
|
const oauthBunq = new bunq.BunqAccount({
|
|
|
|
apiKey: 'test-oauth-token',
|
|
|
|
deviceName: 'OAuth Test App',
|
|
|
|
environment: 'SANDBOX',
|
|
|
|
isOAuthToken: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Test that ensureValidSession doesn't try to refresh OAuth tokens
|
|
|
|
try {
|
|
|
|
await oauthBunq.apiContext.ensureValidSession();
|
|
|
|
console.log('OAuth session management test passed');
|
|
|
|
} catch (error) {
|
|
|
|
console.log('OAuth session test completed');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-07-22 21:18:41 +00:00
|
|
|
tap.test('should handle OAuth tokens without private key errors', async () => {
|
|
|
|
const oauthBunq = new bunq.BunqAccount({
|
|
|
|
apiKey: 'test-oauth-token',
|
|
|
|
deviceName: 'OAuth Test App',
|
|
|
|
environment: 'SANDBOX',
|
|
|
|
isOAuthToken: true
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Initialize (should skip session creation)
|
|
|
|
await oauthBunq.init();
|
|
|
|
|
|
|
|
// Try to make a request (should skip signing)
|
|
|
|
// This would have thrown "Private key not generated yet" before the fix
|
|
|
|
const httpClient = oauthBunq.apiContext.getHttpClient();
|
|
|
|
|
|
|
|
// Test that HTTP client is in OAuth mode and won't try to sign
|
|
|
|
console.log('OAuth HTTP client test passed - no private key errors');
|
|
|
|
} catch (error) {
|
|
|
|
// Expected to fail with network/auth error, not private key error
|
|
|
|
if (error.message && error.message.includes('Private key not generated')) {
|
|
|
|
throw new Error('OAuth mode should not require private keys');
|
|
|
|
}
|
|
|
|
console.log('OAuth private key test completed (expected network failure)');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-07-22 21:10:41 +00:00
|
|
|
tap.start();
|