Skip to content

Commit a3cc9a7

Browse files
committed
fixed e2e tests for the api
1 parent 6d47c79 commit a3cc9a7

6 files changed

Lines changed: 399 additions & 95 deletions

File tree

apps/truvera-api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ EXPOSE 3000
7979

8080
# Health check
8181
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
82-
CMD node -e "process.exit(0)" || exit 1
82+
CMD node -e "fetch('http://127.0.0.1:3000/health').then((response) => process.exit(response.ok ? 0 : 1)).catch(() => process.exit(1))"
8383

8484
# Run the MCP service
8585
CMD ["node", "dist/index.js"]

apps/truvera-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"lint:fix": "eslint . --ext .ts --fix",
1515
"smoke": "tsx tests/smoke-list-tools.ts",
1616
"test": "vitest",
17-
"e2e": "vitest tests/e2e --run",
17+
"e2e": "npm run docker:build && vitest --run tests/e2e/tools-e2e.test.ts",
1818
"docker:build": "cd ../.. && docker build --build-arg BUILD_NUMBER=\"$(cat apps/truvera-api/.buildnumber)\" -t truvera-api-mcp:latest -t truvera-api-mcp:$(cat apps/truvera-api/.buildnumber) -f apps/truvera-api/Dockerfile .",
1919
"docker:run": "docker rm -f truvera-api-mcp || true && docker run -d --name truvera-api-mcp --env-file ./.env -e MCP_MODE=http -e MCP_PORT=3000 -p 3000:3000 truvera-api-mcp:latest"
2020
},

apps/truvera-api/src/features/ap2/tests/e2e/ap2-e2e.test.ts renamed to apps/truvera-api/src/features/ap2/tests/integration/ap2-live.integration.test.ts

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
/**
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.
43
*/
54

65
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
76
import { TruveraClient } from '../../../../clients/index.js';
87
import { AP2Client } from '../../client.js';
98
import { CredentialsClient } from '../../../credentials/client.js';
109
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', () => {
3127
let ap2Client: AP2Client;
3228
let truveraClient: TruveraClient;
3329
let openIdClient: OpenIdClient;
3430
let credentialsClient: CredentialsClient;
3531
const issuedCredentialIds: string[] = [];
3632

3733
beforeAll(() => {
38-
truveraClient = new TruveraClient(API_KEY as string, API_ENDPOINT);
34+
truveraClient = new TruveraClient(liveApiKey as string, API_ENDPOINT);
3935
openIdClient = new OpenIdClient(truveraClient);
4036
ap2Client = new AP2Client(truveraClient, openIdClient);
4137
credentialsClient = new CredentialsClient(truveraClient);
@@ -68,8 +64,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
6864
}, 60000);
6965

7066
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');
7369

7470
const mandateId = `cart_${Date.now()}`;
7571
const response = await ap2Client.issueCartMandate({
@@ -122,8 +118,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
122118
});
123119

124120
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');
127123

128124
const mandateId = `intent_${Date.now()}`;
129125
const response = await ap2Client.issueIntentMandate({
@@ -178,8 +174,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
178174
console.log('✓ Intent Mandate issued successfully:', credential.id);
179175
});
180176

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');
183179

184180
const mandateId = `intent_minimal_${Date.now()}`;
185181
const response = await ap2Client.issueIntentMandate({
@@ -216,8 +212,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
216212
});
217213

218214
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');
221217

222218
const paymentMandateId = `payment_${Date.now()}`;
223219
const response = await ap2Client.issuePaymentMandate({
@@ -264,8 +260,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
264260
console.log('✓ Payment Mandate (human-present) issued successfully:', credential.id);
265261
});
266262

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');
269265

270266
const paymentMandateId = `payment_autonomous_${Date.now()}`;
271267
const response = await ap2Client.issuePaymentMandate({
@@ -306,8 +302,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
306302
});
307303

308304
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');
311307

312308
// First issue a simple cart mandate to verify
313309
const mandateId = `cart_verify_${Date.now()}`;
@@ -355,8 +351,8 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
355351
});
356352

357353
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');
360356

361357
const mandateId = `cart_offer_${Date.now()}`;
362358
// Omit subject_did to trigger credential offer flow
@@ -401,7 +397,7 @@ describe.skipIf(!shouldRunE2E)('e2e: AP2Client mandate issuance tests', () => {
401397
});
402398

403399
// Log summary at the end
404-
if (shouldRunE2E) {
400+
if (shouldRunLiveIntegrationTests) {
405401
describe('Test Summary', () => {
406402
it('should log issued credential IDs', () => {
407403
console.log('\n=== AP2 E2E Test Summary ===');

apps/truvera-api/src/features/credentials/tests/e2e/credentials-e2e.test.ts renamed to apps/truvera-api/src/features/credentials/tests/integration/credentials-live.integration.test.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import { TruveraClient } from '../../../../../src/clients/index.js';
3-
import dotenv from 'dotenv';
43
import { CredentialsClient } from '../../client.js';
54
import { VerifiableCredential, CredentialIssuer } from '../../../shared/credentials.js';
5+
import {
6+
API_ENDPOINT,
7+
ISSUER_DID,
8+
liveApiKey,
9+
liveTestSkipReason,
10+
shouldRunLiveIntegrationTests,
11+
} from '../../../../../tests/helpers/live-test-gate.js';
612

7-
// Load environment variables from .env (default location)
8-
dotenv.config();
9-
// Optionally override with test-specific values from .env.test or .env.tests
10-
dotenv.config({ path: '.env.test', override: true });
11-
dotenv.config({ path: '.env.tests', override: true });
13+
console.log('Live Integration Test - Truvera API Endpoint:', API_ENDPOINT || 'Not Provided');
14+
console.log('Live Integration Test - Truvera API Key:', liveApiKey ? 'Provided' : 'Not Provided');
15+
if (liveTestSkipReason) {
16+
console.log('Live Integration Test - Skipping:', liveTestSkipReason);
17+
}
1218

13-
const API_KEY = process.env.TRUVERA_API_KEY;
14-
const API_ENDPOINT = process.env.TRUVERA_API_ENDPOINT;
15-
const ISSUER_DID = process.env.TRUVERA_API_ISSUER_DID ?? 'did:example:issuer';
16-
17-
console.log('E2E Test - Truvera API Endpoint:', API_ENDPOINT || 'Not Provided');
18-
console.log('E2E Test - Truvera API Key:', API_KEY ? 'Provided' : 'Not Provided');
19-
20-
// Skip the suite if no API key is provided
21-
const shouldRunE2E = !!API_KEY;
22-
23-
describe.skipIf(!shouldRunE2E)('e2e: CredentialClient tests for the Truvera API', () => {
19+
describe.skipIf(!shouldRunLiveIntegrationTests)('integration: CredentialClient live tests against Truvera API', () => {
2420
let credentialClient: CredentialsClient;
2521
const issuedCredentialIds: string[] = [];
2622

2723
beforeAll(() => {
28-
const client = new TruveraClient(API_KEY as string, API_ENDPOINT);
24+
const client = new TruveraClient(liveApiKey as string, API_ENDPOINT);
2925
credentialClient = new CredentialsClient(client);
3026
});
3127

@@ -55,8 +51,8 @@ describe.skipIf(!shouldRunE2E)('e2e: CredentialClient tests for the Truvera API'
5551
console.log('=====================================\n');
5652
});
5753

58-
it('calls issue_credential and succeeds', { timeout: 30000 }, async () => {
59-
console.log('Starting issue_credential e2e test');
54+
it('calls issue_credential and succeeds', { timeout: 120000 }, async () => {
55+
console.log('Starting issue_credential live integration test');
6056
const response = await credentialClient.issueCredential({
6157
credential: {
6258
type: ['VerifiableCredential', 'TestCredential'],

0 commit comments

Comments
 (0)