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 { // OAuth tokens should go through full initialization flow // (installation → device → session) 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 handle OAuth token session management', async () => { const oauthBunq = new bunq.BunqAccount({ apiKey: 'test-oauth-token', deviceName: 'OAuth Test App', environment: 'SANDBOX', isOAuthToken: true }); // OAuth tokens now behave the same as regular API keys // They go through normal session management try { await oauthBunq.apiContext.ensureValidSession(); console.log('OAuth session management test passed'); } catch (error) { console.log('OAuth session test completed'); } }); tap.test('should handle OAuth tokens through full initialization', async () => { const oauthBunq = new bunq.BunqAccount({ apiKey: 'test-oauth-token', deviceName: 'OAuth Test App', environment: 'SANDBOX', isOAuthToken: true }); try { // OAuth tokens go through full initialization flow // The OAuth token is used as the API key/secret await oauthBunq.init(); // The HTTP client works normally with OAuth tokens (including request signing) const httpClient = oauthBunq.apiContext.getHttpClient(); console.log('OAuth initialization test passed - full flow completed'); } catch (error) { // Expected to fail with invalid token error, not initialization skip console.log('OAuth initialization test completed (expected auth failure with mock token)'); } }); tap.start();