version: 2
jobs:
  test:
    docker:
      - image: node:8.9
      - image: circleci/mongo:4.2

    steps:
      - checkout
      - restore_cache:
          key: dependency-cache-{{ .Branch }}-{{ checksum "package-lock.json" }}
      - run:
          name: Install node modules
          command: npm install
      - save_cache:
          key: dependency-cache-{{ .Branch }}-{{ checksum "package-lock.json" }}
          paths:
            - node_modules
            - /root/.npm
      - run:
          name: Run tests
          command: npm test
      - run:
          name: Codecov
          command: bash <(curl -s https://codecov.io/bash)

workflows:
  version: 2
  tests:
    jobs:
      - test
