Skip to content

Latest commit

 

History

History
278 lines (206 loc) · 7.08 KB

File metadata and controls

278 lines (206 loc) · 7.08 KB

Accord Project Demo Template

An Accord Project template demonstrating contract logic implementation using TypeScript, with flexible CLI tools and extensive testing.

Quick Start

Requirements: Node.js v20 or higher

# Install dependencies
npm install

# Run the demo
npm start

# Generate a contract draft
npm run draft

# Generate a PDF contract
npm run pdf

# Generate a markdown contract file
npm run md

# Generate a JSON business logic response
npm run json

# Test business logic
npm run trigger

# Run tests
npm test

Project Structure

├── index.js                    # Main demo script
├── draft.js                    # Contract generation CLI
├── trigger.js                  # Business logic CLI
├── generate-pdf.js             # PDF generation CLI
├── generate-md.js              # Markdown generation CLI
├── generate-json.js            # JSON response generation CLI
├── list-data-files.js          # Data file explorer
├── test-different-values.js    # Multi-scenario demo
├── data/                       # JSON configuration files
│   ├── template-*.json         # Template configurations
│   └── request-*.json          # Request data files
├── __tests__/                  # Comprehensive test suite
└── archives/                   # Accord Project template

CLI Tools

Draft Operation (Contract Generation)

Generate contract documents from template data:

# Using npm scripts
npm run draft           # Basic template
npm run draft:low       # Low penalty template
npm run draft:high      # High penalty template

# Using Node.js directly
node draft.js data/template-basic.json
node draft.js --help    # Show usage

Trigger Operation (Business Logic)

Execute contract business logic with request data:

# Using npm scripts
npm run trigger         # Basic scenario
npm run trigger:low     # Low penalty + low value
npm run trigger:high    # High penalty + high value

# Using Node.js directly
node trigger.js data/template-basic.json data/request-basic.json
node trigger.js --help  # Show usage

PDF Generation

Generate PDF contracts from template data:

# Using npm scripts
npm run pdf             # Basic template
npm run pdf:low         # Low penalty template
npm run pdf:high        # High penalty template

# Using Node.js directly
node generate-pdf.js data/template-basic.json
node generate-pdf.js data/template-basic.json output/contract.pdf
node generate-pdf.js --help  # Show usage

Markdown Generation

Generate markdown contract files from template data:

# Using npm scripts
npm run md              # Basic template
npm run md:low          # Low penalty template
npm run md:high         # High penalty template

# Using Node.js directly
node generate-md.js data/template-basic.json
node generate-md.js data/template-basic.json output/contract.md
node generate-md.js --help  # Show usage

JSON Response Generation

Generate JSON business logic response files from template and request data:

# Using npm scripts
npm run json            # Basic scenario
npm run json:low        # Low penalty + low value
npm run json:high       # High penalty + high value

# Using Node.js directly
node generate-json.js data/template-basic.json data/request-basic.json
node generate-json.js data/template-basic.json data/request-basic.json output/response.json
node generate-json.js --help  # Show usage

Utility Tools

# List available data files
node list-data-files.js

# Run multiple test scenarios
npm run test-values

Data Configuration

Template Data Files

Located in data/ directory:

  • template-basic.json - Default configuration (10.5% penalty, 15-day termination)
  • template-low-penalty.json - Conservative (5% penalty, 30-day termination)
  • template-high-penalty.json - Aggressive (15% penalty, 7-day termination)

Request Data Files

  • request-basic.json - $100 goods value
  • request-low-value.json - $50 goods value
  • request-high-value.json - $1000 goods value

Example Template Format

{
  "$class": "io.clause.latedeliveryandpenalty@0.1.0.TemplateModel",
  "forceMajeure": true,
  "penaltyDuration": {
    "$class": "org.accordproject.time@0.3.0.Duration",
    "amount": 2,
    "unit": "days"
  },
  "penaltyPercentage": 10.5,
  "capPercentage": 55,
  "termination": {
    "$class": "org.accordproject.time@0.3.0.Duration",
    "amount": 15,
    "unit": "days"
  },
  "fractionalPart": "days",
  "clauseId": "your-clause-id",
  "$identifier": "your-clause-id"
}

Example Request Format

{
  "goodsValue": 100
}

Testing

Comprehensive test suite with CLI integration testing:

# Run all tests
npm test

# Run in watch mode
npm run test:watch

# Run specific test file
npm test __tests__/trigger.test.js

Test Coverage

  • CLI Integration Tests - Tests actual command-line usage
  • Error Handling - Invalid files, missing arguments, malformed JSON
  • Edge Cases - Boundary conditions, different data formats
  • Output Validation - Correct formatting, exit codes, error messages

Note: Coverage metrics are not meaningful for CLI tools tested via process spawning. The integration tests provide comprehensive validation of real-world usage scenarios.

Example Scenarios

Template Request Expected Penalty Use Case
Low Penalty Low Value $6.25 Small contracts
Basic Basic $262.50 Standard contracts
High Penalty High Value $3750.00 High-value contracts

Development

Adding New Scenarios

  1. Create new JSON files in data/ directory
  2. Test with CLI tools:
    node draft.js data/your-template.json
    node trigger.js data/your-template.json data/your-request.json

Running Tests During Development

# Watch mode for continuous testing
npm run test:watch

# Test specific functionality
npm test -- --testNamePattern="should handle"

Key Features

  • Flexible Configuration - JSON-based template and request data
  • CLI Tools - Easy-to-use command-line interfaces
  • Comprehensive Testing - Full CLI integration test coverage
  • Multiple Output Formats - Markdown, HTML, PDF contract generation
  • PDF Generation - Direct PDF output from template data
  • JSON Response Generation - Business logic responses saved to files
  • Business Logic Engine - Penalty calculations and contract logic
  • Scenario Testing - Pre-configured test cases and combinations
  • Data Exploration - Built-in tools to explore available configurations

Usage Patterns

For Development

npm run test:watch    # Continuous testing
node list-data-files.js  # Explore available data

For Demos

npm start            # Full demonstration
npm run test-values  # Multiple scenarios

For Integration

# Custom scenarios
echo '{"goodsValue": 5000}' > data/custom-request.json
node trigger.js data/template-high-penalty.json data/custom-request.json