name:  Run tests for "aqua ipfs integration" project

on:
    push:

jobs:
    build:
        runs-on: ubuntu-latest

        strategy:
            matrix:
                node-version: [16.x]
                project: [web, nodejs]
            fail-fast: false

        steps:
            - uses: actions/checkout@v2

            ### Prepare cargo & toolchains
            - uses: actions/cache@v2
              with:
                    path: |
                        ~/.cargo/registry
                        ~/.cargo/git
                        ~/.cargo/bin
                        target
                    key: ${{ runner.os }}-cargo-v2-${{ hashFiles('**/Cargo.lock') }}
            - name: Install Rust toolchain with wasm32-unknown-unknown
              uses: actions-rs/toolchain@v1
              with:
                    toolchain: nightly-2022-06-27
                    target: wasm32-unknown-unknown
                    profile: minimal
                    override: true
            - name: Install wasm32-wasi
              uses: actions-rs/toolchain@v1
              with:
                toolchain: nightly-2022-06-27
                target: wasm32-wasi
                profile: minimal

            - name: Install marine
              run: cargo install marine || true

            - uses: actions/cache@v2
              with:
                  path: ~/.npm
                  key: ${{ runner.os }}-v1-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
                  restore-keys: |
                      ${{ runner.os }}-v1-node-${{ matrix.node-version }}

            - name: Setup Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node-version }}

            ### === Rust tests ===
            - name: run tests
              working-directory:
                ./aqua-examples/aqua-ipfs-integration
              env:
                  CI: true
              run: |
                npm i
                CI=false npm run build
                npm run test -w ${{ matrix.project }}
