import { BaseE2ETest } from '../../lib/base-test'; import { testData } from '../../config/test-data-helpers'; class AccountsE2ETest extends BaseE2ETest { async runWhoamiCommand() { return this.execute(['accounts', 'whoami']); } async runWhoisCommand(trackerId: string, availabilityZone?: string) { const args = ['accounts', 'whois', trackerId]; if (availabilityZone) { args.push(`-a=${availabilityZone}`); } return this.execute(args); } async runWhoisCommandWithoutArgs() { return this.execute(['accounts', 'whois']); } // Public wrapper methods to access protected assertions public checkSuccess(result: any) { this.assertSuccess(result); } public checkOutputMatchesBaseline(result: any, baselinePath: string) { this.assertOutputMatchesBaseline(result, baselinePath); } public checkFailure(result: any) { this.assertFailure(result); } public checkOutputContains(result: any, text: string) { this.assertOutputContains(result, text); } public executePublic(args: string[], options?: any) { return this.execute(args, options); } public clearHistory() { this.cliExecutor.clearProcessHistory(); } } describe('Accounts Commands E2E Tests', () => { let testInstance: AccountsE2ETest; beforeAll(() => { testInstance = new AccountsE2ETest(); }); afterAll(async () => { if (testInstance) { await testInstance.cleanup(); } }); afterEach(() => { // Clean up process history after each test if (testInstance) { testInstance.clearHistory(); } }); describe('accounts whoami', () => { it('should return current user information successfully', async () => { const result = await testInstance.runWhoamiCommand(); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); // Verify key properties exist with valid values (order-independent) expect(result.stdout).toMatch(/Active environment: \w+/); expect(result.stdout).toMatch(/id: [a-f0-9-]{36}/); // UUID format expect(result.stdout).toMatch(/email: \S+@\S+/); // Email format expect(result.stdout).toMatch(/role: \w+/); expect(result.stdout).toMatch(/githubUsername: \S+/); expect(result.stdout).toMatch(/vendor: \S+/); expect(result.stdout).toMatch(/personal_apps:/); expect(result.stdout).toMatch(/accounts:/); expect(result.stdout).toMatch(/createdAt:/); expect(result.stdout).toMatch(/vendor_apps:/); }); it('should complete within reasonable time', async () => { const result = await testInstance.runWhoamiCommand(); expect(result.executionTime).toBeLessThan(10000); // 10 seconds expect(result.timedOut).toBe(false); }); }); describe('accounts whois', () => { const TEST_TRACKER_ID = testData.trackerId; it('should return account information for valid tracker ID', async () => { const result = await testInstance.runWhoisCommand(TEST_TRACKER_ID); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); // Check baseline format testInstance.checkOutputMatchesBaseline(result, 'accounts/whois.txt'); }); it('should work with availability zone parameter', async () => { const result = await testInstance.runWhoisCommand(TEST_TRACKER_ID, 'us'); expect(result.exitCode).toBe(0); expect(result.stdout).toBeTruthy(); }); it('should handle non-existent tracker ID gracefully', async () => { const result = await testInstance.runWhoisCommand('nonexistent-tracker-id'); expect(result.exitCode).toBe(0); expect(result.stdout).toContain('No accounts matching search term'); }); it('should fail when tracker ID parameter is missing', async () => { const result = await testInstance.runWhoisCommandWithoutArgs(); expect(result.exitCode).not.toBe(0); expect(result.stderr).toBeTruthy(); }); }); });