version: 2.1

commands:
  install-and-cache:
    description: Install dependencies with a parameterised cache key
    parameters:
      cache-prefix:
        type: string
        default: deps
      run-audit:
        type: boolean
        default: false
    steps:
      - restore_cache:
          keys:
            - << parameters.cache-prefix >>-{{ checksum "package-lock.json" }}
      - run: npm ci
      - when:
          condition: << parameters.run-audit >>
          steps:
            - run: npm run check-deps

jobs:
  verify:
    parameters:
      suite:
        type: enum
        enum: [unit, integration, contract]
    docker:
      - image: registry.example.invalid/ci/node:20
    steps:
      - checkout
      - install-and-cache:
          cache-prefix: verify
          run-audit: true
      - run: npm run test:<< parameters.suite >>

workflows:
  verify-all:
    jobs:
      - verify:
          name: verify-<< matrix.suite >>
          matrix:
            parameters:
              suite: [unit, integration, contract]
