|
1 | 1 | /** |
2 | | - * AP2 E2E Tests |
3 | | - * End-to-end tests for issuing and verifying AP2 mandates using real Truvera API |
| 2 | + * AP2 live integration tests against the real Truvera API. |
4 | 3 | */ |
5 | 4 |
|
6 | 5 | import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
7 | 6 | import { TruveraClient } from '../../../../clients/index.js'; |
8 | 7 | import { AP2Client } from '../../client.js'; |
9 | 8 | import { CredentialsClient } from '../../../credentials/client.js'; |
10 | 9 | import { OpenIdClient } from '../../../openid/client.js'; |
11 | | -import dotenv from 'dotenv'; |
12 | | - |
13 | | -// Load environment variables from .env (default location) |
14 | | -dotenv.config(); |
15 | | -// Optionally override with test-specific values from .env.test |
16 | | -dotenv.config({ path: '.env.test', override: true }); |
17 | | - |
18 | | -const API_KEY = process.env.TRUVERA_API_KEY; |
19 | | -const API_ENDPOINT = process.env.TRUVERA_API_ENDPOINT; |
20 | | -const ISSUER_DID = process.env.TRUVERA_API_ISSUER_DID ?? 'did:example:issuer'; |
21 | | -const SUBJECT_DID = process.env.TRUVERA_API_SUBJECT_DID ?? 'did:example:subject'; |
22 | | - |
23 | | -console.log('AP2 E2E Test - Truvera API Endpoint:', API_ENDPOINT || 'Not Provided'); |
24 | | -console.log('AP2 E2E Test - Truvera API Key:', API_KEY ? 'Provided' : 'Not Provided'); |
25 | | -console.log('AP2 E2E Test - Issuer DID:', ISSUER_DID); |
26 | | - |
27 | | -// Skip the suite if no API key is provided |
28 | | -const shouldRunE2E = !!API_KEY; |
29 | | - |
30 | | -describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
| 10 | +import { |
| 11 | + API_ENDPOINT, |
| 12 | + ISSUER_DID, |
| 13 | + SUBJECT_DID, |
| 14 | + liveApiKey, |
| 15 | + liveTestSkipReason, |
| 16 | + shouldRunLiveIntegrationTests, |
| 17 | +} from '../../../../../tests/helpers/live-test-gate.js'; |
| 18 | + |
| 19 | +console.log('AP2 Live Integration Test - Truvera API Endpoint:', API_ENDPOINT || 'Not Provided'); |
| 20 | +console.log('AP2 Live Integration Test - Truvera API Key:', liveApiKey ? 'Provided' : 'Not Provided'); |
| 21 | +console.log('AP2 Live Integration Test - Issuer DID:', ISSUER_DID); |
| 22 | +if (liveTestSkipReason) { |
| 23 | + console.log('AP2 Live Integration Test - Skipping:', liveTestSkipReason); |
| 24 | +} |
| 25 | + |
| 26 | +describe.skipIf(!shouldRunLiveIntegrationTests)('integration: AP2Client live mandate tests', () => { |
31 | 27 | let ap2Client: AP2Client; |
32 | 28 | let truveraClient: TruveraClient; |
33 | 29 | let openIdClient: OpenIdClient; |
34 | 30 | let credentialsClient: CredentialsClient; |
35 | 31 | const issuedCredentialIds: string[] = []; |
36 | 32 |
|
37 | 33 | beforeAll(() => { |
38 | | - truveraClient = new TruveraClient(API_KEY as string, API_ENDPOINT); |
| 34 | + truveraClient = new TruveraClient(liveApiKey as string, API_ENDPOINT); |
39 | 35 | openIdClient = new OpenIdClient(truveraClient); |
40 | 36 | ap2Client = new AP2Client(truveraClient, openIdClient); |
41 | 37 | credentialsClient = new CredentialsClient(truveraClient); |
@@ -68,8 +64,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
68 | 64 | }, 60000); |
69 | 65 |
|
70 | 66 | describe('Cart Mandate (Human-Present)', () => { |
71 | | - it('should issue a cart mandate successfully', { timeout: 30000 }, async () => { |
72 | | - console.log('Starting issue Cart Mandate e2e test'); |
| 67 | + it('should issue a cart mandate successfully', { timeout: 120000 }, async () => { |
| 68 | + console.log('Starting issue Cart Mandate live integration test'); |
73 | 69 |
|
74 | 70 | const mandateId = `cart_${Date.now()}`; |
75 | 71 | const response = await ap2Client.issueCartMandate({ |
@@ -122,8 +118,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
122 | 118 | }); |
123 | 119 |
|
124 | 120 | describe('Intent Mandate (Human-Not-Present)', () => { |
125 | | - it('should issue an intent mandate successfully', { timeout: 30000 }, async () => { |
126 | | - console.log('Starting issue Intent Mandate e2e test'); |
| 121 | + it('should issue an intent mandate successfully', { timeout: 120000 }, async () => { |
| 122 | + console.log('Starting issue Intent Mandate live integration test'); |
127 | 123 |
|
128 | 124 | const mandateId = `intent_${Date.now()}`; |
129 | 125 | const response = await ap2Client.issueIntentMandate({ |
@@ -178,8 +174,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
178 | 174 | console.log('✓ Intent Mandate issued successfully:', credential.id); |
179 | 175 | }); |
180 | 176 |
|
181 | | - it('should issue a minimal intent mandate successfully', { timeout: 30000 }, async () => { |
182 | | - console.log('Starting issue minimal Intent Mandate e2e test'); |
| 177 | + it('should issue a minimal intent mandate successfully', { timeout: 120000 }, async () => { |
| 178 | + console.log('Starting issue minimal Intent Mandate live integration test'); |
183 | 179 |
|
184 | 180 | const mandateId = `intent_minimal_${Date.now()}`; |
185 | 181 | const response = await ap2Client.issueIntentMandate({ |
@@ -216,8 +212,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
216 | 212 | }); |
217 | 213 |
|
218 | 214 | describe('Payment Mandate (Network Visibility)', () => { |
219 | | - it('should issue a payment mandate for human-present transaction', { timeout: 90000 }, async () => { |
220 | | - console.log('Starting issue Payment Mandate (human-present) e2e test'); |
| 215 | + it('should issue a payment mandate for human-present transaction', { timeout: 180000 }, async () => { |
| 216 | + console.log('Starting issue Payment Mandate (human-present) live integration test'); |
221 | 217 |
|
222 | 218 | const paymentMandateId = `payment_${Date.now()}`; |
223 | 219 | const response = await ap2Client.issuePaymentMandate({ |
@@ -264,8 +260,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
264 | 260 | console.log('✓ Payment Mandate (human-present) issued successfully:', credential.id); |
265 | 261 | }); |
266 | 262 |
|
267 | | - it('should issue a payment mandate for human-not-present transaction', { timeout: 90000 }, async () => { |
268 | | - console.log('Starting issue Payment Mandate (human-not-present) e2e test'); |
| 263 | + it('should issue a payment mandate for human-not-present transaction', { timeout: 180000 }, async () => { |
| 264 | + console.log('Starting issue Payment Mandate (human-not-present) live integration test'); |
269 | 265 |
|
270 | 266 | const paymentMandateId = `payment_autonomous_${Date.now()}`; |
271 | 267 | const response = await ap2Client.issuePaymentMandate({ |
@@ -306,8 +302,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
306 | 302 | }); |
307 | 303 |
|
308 | 304 | describe('Mandate Verification', () => { |
309 | | - it('should verify an issued mandate successfully', { timeout: 30000 }, async () => { |
310 | | - console.log('Starting verify mandate e2e test'); |
| 305 | + it('should verify an issued mandate successfully', { timeout: 120000 }, async () => { |
| 306 | + console.log('Starting verify mandate live integration test'); |
311 | 307 |
|
312 | 308 | // First issue a simple cart mandate to verify |
313 | 309 | const mandateId = `cart_verify_${Date.now()}`; |
@@ -355,8 +351,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
355 | 351 | }); |
356 | 352 |
|
357 | 353 | describe('Credential Offer Flow (QR Code)', () => { |
358 | | - it('should create a credential offer when subject_did is omitted', { timeout: 90000 }, async () => { |
359 | | - console.log('Starting credential offer flow e2e test'); |
| 354 | + it('should create a credential offer when subject_did is omitted', { timeout: 180000 }, async () => { |
| 355 | + console.log('Starting credential offer flow live integration test'); |
360 | 356 |
|
361 | 357 | const mandateId = `cart_offer_${Date.now()}`; |
362 | 358 | // Omit subject_did to trigger credential offer flow |
@@ -401,7 +397,7 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => { |
401 | 397 | }); |
402 | 398 |
|
403 | 399 | // Log summary at the end |
404 | | - if (shouldRunE2E) { |
| 400 | + if (shouldRunLiveIntegrationTests) { |
405 | 401 | describe('Test Summary', () => { |
406 | 402 | it('should log issued credential IDs', () => { |
407 | 403 | console.log('\n=== AP2 E2E Test Summary ==='); |
|
0 commit comments