Markdown Converter
Agent skill for markdown-converter
This document contains a series of prompts for a code-generation LLM to implement the Receipt Points API in a test-driven manner. Each prompt builds on the previous ones, ensuring incremental progress and early testing.
Sign in to like and favorite skills
This document contains a series of prompts for a code-generation LLM to implement the Receipt Points API in a test-driven manner. Each prompt builds on the previous ones, ensuring incremental progress and early testing.
I'm building a Receipt Points API that processes receipts and awards points based on rules. Let's start by setting up the project foundation. Please create a Node.js project with TypeScript that includes: 1. A package.json with necessary dependencies for: - Express.js for the web server - TypeScript for type safety - Jest for testing - ESLint and Prettier for code quality 2. A basic Express server that: - Listens on port 8080 - Has a health check endpoint at GET /health that returns 200 OK - Includes middleware for JSON parsing - Has a basic error handling structure 3. A Dockerfile and docker-compose.yml that: - Builds the application - Exposes port 8080 - Uses a Node.js base image - Follows best practices for Docker 4. A simple Jest test that verifies the health check endpoint works The application should be runnable with "docker compose up" and should be accessible at localhost:8080. Please provide all necessary files with proper configuration.
Now let's implement the core data models and validation for our Receipt Points API. Building on our existing project setup, we need to define interfaces and validation for receipts, receipt items, rules, and conversion rates. Please create: 1. TypeScript interfaces for: - Receipt (with fields: id, userId, storeName, purchaseDate, items, total) - ReceiptItem (with fields: id, description, quantity, price) - Rule (base interface) - StoreNameMatchRule (extends Rule, with fields: id, storeName, points) - ItemMatchRule (extends Rule, with fields: id, itemIds, ratePercent) - ConversionRate (with field: pointsPerDollar) 2. Validation utilities that: - Validate Receipt objects (required fields, positive values, etc.) - Validate ReceiptItem objects (required fields, positive values) - Validate StoreNameMatchRule objects (required fields, positive values) - Validate ItemMatchRule objects (required fields, positive values) - Validate ConversionRate objects (positive pointsPerDollar) 3. Unit tests for all validation functions that: - Test valid inputs - Test invalid inputs (missing fields, negative values, etc.) - Test edge cases The validation should follow these rules: - Receipt: id may be omitted (server will generate), userId/storeName are required non-blank strings, purchaseDate is required ISO-8601 string, items array must have at least one item, total is required positive number - ReceiptItem: id and description are required non-blank strings, quantity and price must be positive numbers - StoreNameMatchRule: id and storeName are required non-blank strings, points must be positive integer - ItemMatchRule: id is required non-blank string, itemIds must be non-empty array of strings, ratePercent must be positive integer - ConversionRate: pointsPerDollar must be positive integer Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's implement the in-memory storage for our Receipt Points API. We need repositories to store and retrieve receipts, rules, and the conversion rate. Please create: 1. Repository interfaces: - ReceiptRepository: define methods for storing, retrieving, and checking existence of receipts - RuleRepository: define methods for storing, retrieving, and getting all rules of specific types - ConversionRateRepository: define methods for setting and getting the conversion rate 2. In-memory implementations of these repositories: - InMemoryReceiptRepository: use a Map to store receipts by ID - InMemoryRuleRepository: use Maps to store rules by ID and type - InMemoryConversionRateRepository: store a single conversion rate value (default: 1000) 3. Unit tests for all repository implementations that: - Test storing and retrieving items - Test overwriting existing items - Test retrieving non-existent items - Test getting all items of a specific type - Test the default conversion rate The repositories should handle these specific requirements: - Receipt repository: should generate UUIDs for receipts with empty/missing IDs - Rule repository: should allow retrieving all rules of a specific type (StoreNameMatch or ItemMatch) - Conversion rate repository: should have a default value of 1000 for pointsPerDollar Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Now let's implement the store name normalization service for our Receipt Points API. This service will be used to normalize store names for comparison when applying StoreNameMatch rules. Please create: 1. A StoreNameService with these functions: - normalize(storeName: string): string - Normalizes a store name according to the rules - isMatch(normalizedRuleStoreName: string, normalizedReceiptStoreName: string): boolean - Checks if the rule store name is a substring of the receipt store name 2. The normalization should follow these rules: - Convert to lowercase - Collapse all runs of whitespace to a single space - Remove single quotes (') and hyphens (-) - Trim leading and trailing whitespace 3. Unit tests for the service that: - Test normalization of various store name formats - Test matching with examples from the specification - Test edge cases (empty strings, strings with only special characters, etc.) Examples from the specification: - Rule "walmart" should match receipt "WALMART SUPERCENTER" -> true - Rule "starbucks" should match "O'Hare - Starbucks" -> true Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's implement the basic structure of the points calculation service for our Receipt Points API. This service will calculate points for receipts based on applicable rules. Please create: 1. A PointsCalculationService interface with these methods: - calculatePoints(receipt: Receipt): number - Calculates total points for a receipt - calculatePointsForStoreNameMatch(receipt: Receipt, rule: StoreNameMatchRule): number - Calculates points from a StoreNameMatch rule - calculatePointsForItemMatch(receipt: Receipt, rule: ItemMatchRule, pointsPerDollar: number): number - Calculates points from an ItemMatch rule 2. A basic implementation of this service that: - Injects the necessary repositories (RuleRepository, ConversionRateRepository) - Injects the StoreNameService - Implements skeleton methods that return 0 (we'll fill in the actual logic in later steps) - Has proper dependency injection setup 3. Unit tests for the service structure that: - Test initialization with dependencies - Test that the skeleton methods can be called with appropriate parameters - Verify the service can be integrated with the repositories This is just setting up the structure - we'll implement the actual calculation logic in the next steps. Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Now let's implement the StoreNameMatch rule processing in our points calculation service. This will award points when a normalized store name from a rule is a substring of the normalized store name from a receipt. Please enhance the PointsCalculationService to: 1. Implement the calculatePointsForStoreNameMatch method that: - Takes a receipt and a StoreNameMatchRule - Uses the StoreNameService to normalize both store names - Checks if the rule's store name is a substring of the receipt's store name - Returns the rule's points if there's a match, otherwise returns 0 2. Update the calculatePoints method to: - Retrieve all StoreNameMatch rules from the rule repository - Apply each rule to the receipt using calculatePointsForStoreNameMatch - Sum the points from all matching rules - For now, only include StoreNameMatch rules (we'll add ItemMatch in the next step) 3. Write comprehensive unit tests that: - Test matching with various store names - Test non-matching cases - Test with multiple rules where some match and some don't - Test edge cases (empty store names, special characters, etc.) Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's implement the ItemMatch rule processing in our points calculation service. This will award points for receipt items that match the itemIds specified in the rule, using the formula: ceil(quantity × price × pointsPerDollar × ratePercent / 100). Please enhance the PointsCalculationService to: 1. Implement the calculatePointsForItemMatch method that: - Takes a receipt, an ItemMatchRule, and the pointsPerDollar value - For each item in the receipt, checks if its ID is in the rule's itemIds - For matching items, calculates points using the formula: ceil(quantity × price × pointsPerDollar × ratePercent / 100) - Sums the points from all matching items - Returns the total points 2. Update the calculatePoints method to: - Retrieve the current pointsPerDollar from the ConversionRateRepository - Retrieve all ItemMatch rules from the rule repository - Apply each rule to the receipt using calculatePointsForItemMatch - Add these points to the sum from StoreNameMatch rules 3. Write comprehensive unit tests that: - Test with various item quantities and prices - Test with different ratePercent values - Verify the rounding behavior (ceiling function) - Test with multiple matching items in a receipt - Test with no matching items - Test edge cases Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Now let's finalize the points calculation service by ensuring it correctly combines points from both rule types and handles the conversion rate properly. Please enhance the PointsCalculationService to: 1. Refine the calculatePoints method to: - Retrieve all rules (both StoreNameMatch and ItemMatch) from the repository - Retrieve the current pointsPerDollar from the ConversionRateRepository - Apply each rule type appropriately - Sum all points from both rule types - Return the total as an integer 2. Ensure the service correctly handles: - Empty rule sets - Missing or invalid conversion rates (use default 1000) - Edge cases in the calculation 3. Write comprehensive integration tests that: - Test with combinations of both rule types - Test with different conversion rates - Verify the total calculation matches expected results - Test with the examples from the specification Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's implement the receipt endpoints for our API. We need to create endpoints for creating/updating receipts and retrieving receipts by ID. Please implement: 1. A ReceiptController with these endpoints: - POST /receipt - Create or update a receipt - GET /receipt/:id - Retrieve a receipt by ID 2. For the POST /receipt endpoint: - Validate the incoming receipt data - Generate an ID if one is not provided - Store the receipt in the repository - Return 200 OK with the receipt ID 3. For the GET /receipt/:id endpoint: - Retrieve the receipt from the repository - Return 200 OK with the receipt if found - Return 404 Not Found with an empty body if not found 4. Add proper error handling: - Return 400 Bad Request for invalid input (missing required fields, negative values, etc.) - Include appropriate error messages 5. Write comprehensive tests for both endpoints: - Test successful creation with valid data - Test successful creation with generated ID - Test successful retrieval of existing receipt - Test 404 response for non-existent receipt - Test validation errors Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Now let's implement the endpoint for calculating points for a receipt. This endpoint will use our PointsCalculationService to calculate points for a given receipt ID. Please implement: 1. Add to the ReceiptController: - GET /receipt/:id/points - Calculate points for a receipt 2. For the GET /receipt/:id/points endpoint: - Retrieve the receipt from the repository - Return 404 Not Found with an empty body if the receipt doesn't exist - Use the PointsCalculationService to calculate points for the receipt - Return 200 OK with the points in the format: { "points": 1234 } 3. Write comprehensive tests for this endpoint: - Test successful points calculation for existing receipt - Test with various rule combinations - Test 404 response for non-existent receipt - Test edge cases Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's implement the rule endpoints for our API. We need to create endpoints for creating/updating both types of rules: StoreNameMatch and ItemMatch. Please implement: 1. A RuleController with these endpoints: - POST /rule/StoreNameMatch - Create or update a StoreNameMatch rule - POST /rule/ItemMatch - Create or update an ItemMatch rule 2. For the POST /rule/StoreNameMatch endpoint: - Validate the incoming rule data (id, storeName, points) - Store the rule in the repository - Return 202 Accepted with an empty body 3. For the POST /rule/ItemMatch endpoint: - Validate the incoming rule data (id, itemIds, ratePercent) - Store the rule in the repository - Return 202 Accepted with an empty body 4. Add proper error handling: - Return 400 Bad Request for invalid input (missing required fields, negative values, etc.) - Return 400 Bad Request for unknown rule types - Include appropriate error messages 5. Write comprehensive tests for both endpoints: - Test successful creation with valid data - Test validation errors - Test rule overwriting behavior - Test with edge cases Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's implement the conversion rate endpoint for our API. This endpoint will allow setting the global pointsPerDollar value used in ItemMatch rule calculations. Please implement: 1. A ConversionRateController with this endpoint: - POST /conversionRate - Set the global pointsPerDollar value 2. For the POST /conversionRate endpoint: - Validate the incoming data (pointsPerDollar must be a positive integer) - Store the conversion rate in the repository - Return 202 Accepted with an empty body 3. Add proper error handling: - Return 400 Bad Request for invalid input (missing field, non-positive value, etc.) - Include appropriate error messages 4. Write comprehensive tests for this endpoint: - Test successful update with valid data - Test validation errors - Test the effect on subsequent points calculations - Test with edge cases Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's enhance the error handling across our Receipt Points API to ensure consistent error responses and proper handling of all error scenarios. Please implement: 1. A global error handling middleware that: - Catches all unhandled errors in the application - Formats error responses according to the specification - Sets appropriate HTTP status codes 2. Standardize error responses: - 400 Bad Request: { "message": "specific error message" } for validation errors - 404 Not Found: empty body for resource not found - 500 Internal Server Error: { "message": "internal error" } for unhandled errors 3. Update all controllers to use this consistent error handling: - Ensure ReceiptController uses proper error responses - Ensure RuleController uses proper error responses - Ensure ConversionRateController uses proper error responses 4. Write comprehensive tests for error handling: - Test validation error responses - Test not found error responses - Test internal error responses - Test edge cases Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Now let's create comprehensive integration tests for our Receipt Points API to ensure all components work together correctly. Please implement: 1. Integration tests that test complete workflows: - Create a receipt, retrieve it, and calculate its points - Create rules of both types and verify they affect points calculation - Update the conversion rate and verify it affects subsequent calculations 2. Test with the sample data from the specification: - Use the sample receipt, StoreNameMatch rule, and ItemMatch rule - Verify the behavior matches the expected results 3. Test edge cases and error scenarios: - Test with invalid inputs - Test with non-existent resources - Test with boundary conditions 4. Create a test utility that: - Sets up a test environment - Provides helper functions for common test operations - Cleans up after tests Please provide all necessary files with proper TypeScript typing and comprehensive tests.
Let's finalize our Receipt Points API by reviewing the code, optimizing performance, and adding documentation. Please: 1. Review and optimize the code: - Check for any performance issues - Ensure code quality and readability - Remove any unused code or dependencies 2. Finalize the Docker configuration: - Ensure the Dockerfile follows best practices - Verify the docker-compose.yml file is correct - Add any necessary environment variables 3. Create API documentation: - Document all endpoints with request/response examples - Explain the business rules and calculations - Provide usage instructions 4. Add a README.md that includes: - Project overview - Setup instructions - API documentation - Testing instructions - Any other relevant information 5. Perform a final end-to-end test to verify all requirements are met: - Test all endpoints - Verify points calculation - Ensure Docker setup works correctly Please provide all necessary files to complete the project.
These prompts are designed to guide a code-generation LLM through the process of implementing the Receipt Points API in a test-driven, incremental manner. Each prompt builds on the previous ones, ensuring that the code is developed in small, testable chunks that gradually build up to the complete application.