Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 92 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ interface Project {
[key: string]: any;
}

interface ApiResponse {
data?: Project[];
interface Test {
id: number;
name: string;
folder_name?: string;
steps?: Array<{
description: string;
expected_result?: string;
}>;
[key: string]: any;
}

interface ApiResponse<T = any> {
data?: T[];
error?: string;
}

Expand Down Expand Up @@ -42,7 +53,7 @@ class TestQualityClient {
throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json() as ApiResponse;
const data = await response.json() as ApiResponse<Project>;

if (data.error) {
throw new Error(data.error);
Expand All @@ -56,6 +67,40 @@ class TestQualityClient {
throw new Error('Failed to fetch projects: Unknown error');
}
}

async getTests(): Promise<Test[]> {
try {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};

if (this.apiKey) {
headers['Authorization'] = `Bearer ${this.apiKey}`;
}

const response = await fetch(`${this.baseUrl}/api/test`, {
method: 'GET',
headers,
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json() as ApiResponse<Test>;

if (data.error) {
throw new Error(data.error);
}

return data.data || [];
} catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to fetch tests: ${error.message}`);
}
throw new Error('Failed to fetch tests: Unknown error');
}
}
}

const program = new Command();
Expand Down Expand Up @@ -100,6 +145,50 @@ program
}
});

program
.command('tests')
.description('List all tests from TestQuality')
.option('-k, --api-key <key>', 'API key for authentication')
.option('-u, --url <url>', 'Base URL for TestQuality API', 'https://api.testquality.com')
.option('-j, --json', 'Output as JSON')
.action(async (options) => {
try {
const client = new TestQualityClient(options.url, options.apiKey);
const tests = await client.getTests();

if (tests.length === 0) {
console.log('No tests found.');
return;
}

if (options.json) {
console.log(JSON.stringify(tests, null, 2));
} else {
console.log('\nTestQuality Tests:');
console.log('==================');
tests.forEach((test, index) => {
console.log(`\n${index + 1}. ${test.name}`);
console.log(` ID: ${test.id}`);
if (test.folder_name) {
console.log(` Folder: ${test.folder_name}`);
}
if (test.steps && test.steps.length > 0) {
console.log(` Steps: ${test.steps.length}`);
test.steps.forEach((step, stepIndex) => {
console.log(` ${stepIndex + 1}. ${step.description}`);
if (step.expected_result) {
console.log(` Expected: ${step.expected_result}`);
}
});
}
});
}
} catch (error) {
console.error('Error:', error instanceof Error ? error.message : 'Unknown error');
process.exit(1);
}
});

program.parse(process.argv);

if (!process.argv.slice(2).length) {
Expand Down
12 changes: 11 additions & 1 deletion tests.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ Production,Run Compiled Version,Run 'yarn start projects' after build,Execute co
Error Handling,Invalid Command,Run 'yarn tq invalid-command',Display error message for unknown command
Error Handling,Missing Required Options,Run command that requires options without providing them,Display appropriate error message
Error Handling,API Response Error,Mock API returning error status,Display HTTP error status message
Error Handling,Malformed JSON Response,Mock API returning invalid JSON,Display parsing error message
Error Handling,Malformed JSON Response,Mock API returning invalid JSON,Display parsing error message
Tests Command,Display Tests Help,Run 'yarn tq tests --help',Display tests command help with available options
Tests Command,Fetch Tests Without Auth,Run 'yarn tq tests' without API key,Either display tests list or authentication error message
Tests Command,Fetch Tests With Auth,Run 'yarn tq tests -k <API_KEY>' with valid API key,Display list of tests from TestQuality API
Tests Command,Fetch Tests JSON Format,Run 'yarn tq tests --json',Output tests in JSON format with proper indentation
Tests Command,Display Test Steps,Run 'yarn tq tests' when tests have steps,Display test name folder and step details with expected results
Tests Command,Custom API URL for Tests,Run 'yarn tq tests -u https://custom.api.url',Attempt to fetch tests from custom URL
Tests Command,Handle Empty Tests List,Run 'yarn tq tests' when no tests exist,Display 'No tests found.' message
Tests Command,Handle Network Error for Tests,Disconnect network and run 'yarn tq tests',Display network error message gracefully
Tests Command,Handle Invalid API Key for Tests,Run 'yarn tq tests -k INVALID_KEY',Display authentication error message
Tests Command,Display Test Folder Information,Run 'yarn tq tests' with tests that have folder_name,Display folder name for each test