Automated API contract and functional tests for the Agify API (https://api.agify.io) using TypeScript, Cucumber, and Playwright.
- Node.js: v20.x or higher
- npm: v10.x or higher
GitHub Actions workflow runs tests on push/PR and uploads HTML reports as artifacts.
-
Clone the repository
-
Install dependencies:
npm install- (Optional) Configure environment variables:
cp .env.example .env
# Edit .env and add your API key if you have onenpm testnpx playwright testnpm run test:reportThe HTML report will be generated in reports/cucumber-report.html.
npx playwright show-reportPlaywright HTML reports are generated in test-results/ directory.
npm run buildnpm run lintThe project includes a comprehensive Playwright configuration (playwright.config.ts) that supports:
- Multi-browser testing (Chromium, Firefox, WebKit)
- API request context with rate limiting
- Environment-based configuration
- HTML reporting
- Retry logic for CI environments
# API base URL (optional)
AGIFY_BASE_URL=https://api.agify.io
# API key for increased rate limits (optional but recommended)
AGIFY_API_KEY=your-api-key-here
# Request timeout (optional, default: 8000ms)
AGIFY_TIMEOUT=8000Get an API key: Visit https://agify.io/store to subscribe and get higher rate limits (1000+ requests/day).
Usage:
# With API key
AGIFY_API_KEY=your-key npm test
# Or create .env file (not committed to git)
echo "AGIFY_API_KEY=your-key" > .env
npm testDefault base URL: https://api.agify.io
The test suite validates:
- Single name requests - Basic age estimation for individual names
- Country-specific requests - Age estimation with country_id parameter for localization
- Multiple names requests - Batch processing of multiple names in single API call
- Missing parameter handling - API behavior when no parameters are provided (422 error)
- Empty name parameter - API handling of empty string name parameter
- Invalid character handling - API processing of special characters (@#$%)
- Invalid country code - API behavior with invalid country_id values
- Mixed valid/invalid inputs - Partial invalid input in batch requests
- Very long names - API handling of excessively long input strings (1000+ characters)
- Stress testing - API behavior with large number of names (100 names)
- HTTP method validation - API rejection of non-GET methods (POST returns 404)
- Response format validation - JSON structure and required fields verification
- Response schema validation - Validates name (string), age (int|null), count (int) fields
- HTTP status codes - Tests 200 (success), 422 (unprocessable entity), 404 (not found)
- Response content-type - Ensures application/json content type
- Response time validation - Performance testing under 2 seconds
- Multi-browser compatibility - Cross-browser testing (Chromium, Firefox, WebKit)
- Array response validation - Batch requests return proper array format
- Error message validation - Correct error messages for missing/invalid parameters
The test suite includes the following specific scenarios:
- Single name request - Basic age estimation for "michael"
- Single name with country_id - Localized age estimation with "US" country code
- Multiple names request - Batch processing of "michael", "matthew", "jane"
- Request with no parameters - Tests 422 error for missing name parameter
- Request with empty name parameter - Tests API handling of empty string
- Request with invalid characters - Tests special characters "@#$%"
- Request with invalid country code - Tests invalid country_id "XYZ"
- Multiple names with partial invalid input - Mixed valid/invalid names
- Request with excessively long name - Tests 1000+ character names
- Request with many names (stress test) - Tests 100 names (expects 422 error)
- Validate HTTP status code 200 - Confirms success status for valid requests
- Validate HTTP status code for invalid requests - Confirms 422 for missing parameters
- Verify response format (JSON structure) - Validates response schema and required fields
- Verify API rejects non-GET methods - Tests POST method rejection (404 error)
- API request context with built-in rate limiting
- Browser-based testing capabilities
- Cross-browser test execution
- Enhanced error handling and retry logic
- Comprehensive HTML reporting
.
├── package.json
├── package-lock.json
├── tsconfig.json
├── playwright.config.ts
├── cucumber.js
├── eslint.config.mjs
├── src/
│ ├── config/
│ │ └── api.ts
│ └── schemas/
│ └── agifyResponse.ts
├── tests/
│ ├── features/
│ │ └── agify.feature
│ ├── steps/
│ │ └── agify.steps.ts
│ └── world/
│ └── customWorld.ts
├── reports/
│ └── cucumber-report.html
├── test-results/
└── README.md
- @cucumber/cucumber (v10.9.0): BDD test framework
- @playwright/test (v1.56.1): Browser automation and API testing
- playwright (v1.56.1): Core Playwright library
- TypeScript (v5.7.2): Type-safe JavaScript
- ts-node (v10.9.2): TypeScript execution
- dotenv (v17.2.3): Environment variable management
- eslint (v9.17.0): Linting with TypeScript support
- @types/node (v20.17.9): Node.js type definitions
The following assumptions were made based on observed API behavior:
-
Empty name parameter: The API accepts
name=(empty string) and returns 200 with a valid response rather than rejecting it as invalid. This is documented in the test scenarios. -
Whitespace-only names: The API accepts names containing only whitespace (e.g., " ") and returns 200 with a valid response.
-
Missing name parameter: The API returns 422 (Unprocessable Entity) when the
nameparameter is completely missing from the request. -
Response time SLA: A 2-second response time threshold was chosen as a reasonable performance baseline for a public API.
-
Very long names: The API was tested with 1000-character names to validate edge case handling.
-
Rate Limiting:
- Free tier: 100 requests per day
- Rate limit resets at midnight UTC
- If you see 429 errors, either wait for reset or get an API key from https://agify.io/store
- With an API key, you get 1000+ requests/day
- Check remaining quota:
curl -I "https://api.agify.io/?name=test"(look forx-rate-limit-remaining)
-
The Agify API does not strictly validate input and accepts empty/whitespace names, returning valid responses rather than client errors. This behavior is documented in the test scenarios.
-
The API returns
age: nullfor names with insufficient data, which is correctly validated by the schema. -
Unicode names are properly handled by the API (tested with José, Özil, 李).
When not rate-limited:
- 14 scenarios (14 passed)
- 59 steps (59 passed)
- Execution time: ~2.3 seconds
Note: If running tests multiple times in quick succession, you may hit the API rate limit. Space out test runs by a few minutes for consistent results.
See reports/cucumber-report.html for detailed test results.