Skip to content

Conversation

@Ujjwal-here
Copy link

This PR adds a new isAlpha validation function that checks if a string contains only alphabetical characters (letters), along with its corresponding API endpoint.

Changes Made

1. New Validation Function (validationFunctions.js)

  • Added isAlpha() static method to the ValidationFunctions class
  • Function returns true if input contains only letters (a-z, A-Z)
  • Function returns false for strings with numbers, spaces, or special characters
  • Includes comprehensive JSDoc documentation with examples

2. New API Endpoint (server.js)

  • Added POST /api/isAlpha endpoint
  • Follows established API patterns and error handling
  • Returns JSON response with boolean result
  • Includes full Swagger documentation

3. Comprehensive Test Coverage

  • Unit Tests (test/unit/isAlpha.test.js): Tests the validation function directly
    • Validates strings with only letters (lowercase, uppercase, mixed case)
    • Tests rejection of strings with numbers, spaces, special characters
    • Covers edge cases like empty strings and mixed content
  • Integration Tests (test/integration/isAlpha.test.js): Tests the API endpoint
    • Validates successful API responses for valid inputs
    • Tests error handling for missing/invalid parameters
    • Ensures proper HTTP status codes

Functionality

The isAlpha function validates that a string contains exclusively alphabetical characters:

  • "hello"true
  • "HelloWorld"true
  • "ABC"true
  • "hello123"false
  • "hello world"false
  • "hello!"false

Testing

Run the new tests with:

# Unit tests only
npm test -- --testPathPattern="isAlpha" --testPathIgnorePatterns="integration"

# All tests
npm test

API Usage

POST /api/isAlpha
Content-Type: application/json

{
  "inputString": "hello"
}

# Response
{
  "result": true
}

Related Issues

Closes #16 - Add API Call and Function for isAlpha

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add API Call and Function for isAlpha

1 participant