diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml deleted file mode 100644 index 51add6871..000000000 --- a/.github/workflows/codecov.yml +++ /dev/null @@ -1,33 +0,0 @@ -on: [push] - -jobs: - rubocop: - runs-on: ubuntu-latest - name: A job to codecov report. - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - run: docker-compose pull - working-directory: docker/development - - uses: satackey/action-docker-layer-caching@v0.0.11 - continue-on-error: true - - run: docker-compose build - working-directory: docker/development - - name: create db - working-directory: docker/development - run: | - docker-compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails db:create" - docker-compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails db:migrate" - docker-compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails db:test:prepare" - - name: Reindex sunspot - working-directory: docker/development - run: | - docker-compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rake sunspot:reindex" - - name: Run tests - working-directory: docker/development - run: docker-compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails spec" - - name: Send test coverage report to codecov.io - uses: codecov/codecov-action@v2 - with: - directory: ./coverage diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 8f4484ac7..ff55d914e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -9,7 +9,7 @@ jobs: - name: Set up Ruby 3 uses: ruby/setup-ruby@v1 with: - ruby-version: 3.1.2 + ruby-version: 3.1.4 - name: Install gems # usual step to install the gems. run: | bin/bundle config path vendor/bundle diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml deleted file mode 100644 index e860bb4dd..000000000 --- a/.github/workflows/test-integration.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Integration tests -on: - push: - branches: - - main - - mampf-next - - production - - experimental - pull_request: -jobs: - e2e-test-job: - name: Run E2E tests & upload results to Cypress - runs-on: ubuntu-latest - timeout-minutes: 30 - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Pull docker images - run: docker compose pull --ignore-buildable - working-directory: docker/run_cypress_tests - - - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching - uses: jpribyl/action-docker-layer-caching@v0.1.1 - continue-on-error: true - - - name: Build docker containers - run: docker compose build - working-directory: docker/run_cypress_tests - - - name: Run integration tests - working-directory: docker/run_cypress_tests - env: - # pass the Dashboard record key as an environment variable - CYPRESS_baseUrl: http://mampf:3000 - CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} - # pass GitHub token to allow accurately detecting a build vs a re-run build - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: docker compose run -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} --entrypoint="" cypress_runner sh -c "while ! curl http://mampf:3000 ; do echo waiting for MaMpf to come online at http://mampf:3000; sleep 3; done; cypress run --record --key ${{ secrets.CYPRESS_RECORD_KEY }}" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..ac0fb3280 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,84 @@ +name: Tests + +on: + push: + branches: + - main + - mampf-next + - production + - experimental + pull_request: + +jobs: + unit-test-job: + name: Execute unit tests & upload to Codecov + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Pull docker images + run: docker compose pull --ignore-buildable + working-directory: docker/run_cypress_tests + + - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching + uses: jpribyl/action-docker-layer-caching@v0.1.1 + continue-on-error: true + + - name: Build docker containers + run: docker compose build + working-directory: docker/run_cypress_tests + - name: Create and migrate DB + run: docker compose run --entrypoint "" mampf sh -c "rake db:create db:migrate db:test:prepare" + working-directory: docker/run_cypress_tests + - name: Reindex sunspot + working-directory: docker/run_cypress_tests + run: | + docker compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rake sunspot:reindex" + + - name: Run unit tests + working-directory: docker/run_cypress_tests + run: docker compose run --entrypoint="" mampf sh -c "RAILS_ENV=test rails spec" + - name: Send test coverage report to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./coverage/coverage.xml + fail_ci_if_error: true + verbose: true + e2e-test-job: + name: Run E2E tests & upload results to Cypress + runs-on: ubuntu-latest + timeout-minutes: 30 + needs: unit-test-job + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Pull docker images + run: docker compose pull --ignore-buildable + working-directory: docker/run_cypress_tests + + - name: Use Docker layer caching # https://github.com/jpribyl/action-docker-layer-caching + uses: jpribyl/action-docker-layer-caching@v0.1.1 + continue-on-error: true + + - name: Build docker containers + run: docker compose build + working-directory: docker/run_cypress_tests + - name: Create and migrate DB + run: docker compose run --entrypoint "" mampf sh -c "rake db:create db:migrate db:test:prepare" + working-directory: docker/run_cypress_tests + - name: Run integration tests + working-directory: docker/run_cypress_tests + env: + # pass the Dashboard record key as an environment variable + CYPRESS_baseUrl: http://mampf:3000 + CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} + # pass GitHub token to allow accurately detecting a build vs a re-run build + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: docker compose run -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} --entrypoint="" cypress_runner sh -c "while ! curl http://mampf:3000 ; do echo waiting for MaMpf to come online at http://mampf:3000; sleep 3; done; cypress run --record --key ${{ secrets.CYPRESS_RECORD_KEY }}" + diff --git a/docker/run_cypress_tests/Dockerfile b/docker/run_cypress_tests/Dockerfile index c02139e80..a21303cd3 100644 --- a/docker/run_cypress_tests/Dockerfile +++ b/docker/run_cypress_tests/Dockerfile @@ -25,13 +25,11 @@ RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xm WORKDIR /usr/src/app COPY ./Gemfile ./Gemfile.lock ./yarn.lock ./package.json /usr/src/app/ -RUN bundle install +RUN bundle install && \ + yarn install --production=false COPY --from=build-pdfcomprezzor /go/src/pdfcomprezzor.wasm /go/src/wasm_exec.js /usr/src/app/public/pdfcomprezzor/ COPY --from=build-pdfcomprezzor /go/src/pdfcomprezzor.wasm /go/src/wasm_exec.js / -COPY Gemfile Gemfile.lock package.json yarn.lock /usr/src/app/ -RUN bundle install && \ - yarn install --production=false COPY ./ /usr/src/app/ RUN RAILS_ENV=test TEST_DATABASE_ADAPTER=postgresql rake assets:precompile diff --git a/docker/run_cypress_tests/docker-compose.yml b/docker/run_cypress_tests/docker-compose.yml index dbc8bb99d..70603e1cd 100644 --- a/docker/run_cypress_tests/docker-compose.yml +++ b/docker/run_cypress_tests/docker-compose.yml @@ -69,6 +69,7 @@ services: - type: bind source: ../../spec/ target: /usr/src/app/spec/ + - ../../coverage:/usr/src/app/coverage depends_on: - db - solr diff --git a/docker/run_tests/Dockerfile b/docker/run_tests/Dockerfile deleted file mode 100644 index fea9a9475..000000000 --- a/docker/run_tests/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM ruby:3.1.4 - -ENV RAILS_ENV=production - -EXPOSE 3000 - -ENTRYPOINT ["/usr/src/app/entrypoint.sh"] - -# https://github.com/nodesource/distributions#installation-instructions -RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \ - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ - apt-get update && apt-get install -y nodejs yarn ffmpeg imagemagick pdftk ghostscript sqlite3 shared-mime-info --no-install-recommends && rm -rf /var/lib/apt/lists/* && apt-get clean - -RUN groupadd -g 501 app && useradd -g 501 -u 501 -m -d /usr/src/app app -WORKDIR /usr/src/app -USER app - -COPY --chown=app:app ./Gemfile ./Gemfile.lock /usr/src/app/ -RUN bundle install -COPY --chown=app:app ./ /usr/src/app/ diff --git a/docker/run_tests/docker-compose.yml b/docker/run_tests/docker-compose.yml deleted file mode 100644 index d93f732b6..000000000 --- a/docker/run_tests/docker-compose.yml +++ /dev/null @@ -1,67 +0,0 @@ ---- -version: '3.4' -services: - redis: - image: "redis:6.2.6-alpine" - - solr: - image: "solr:8.11.1" - container_name: mampf_solr_test - volumes: - - type: bind - source: ../../solr/development/conf/ - target: /solrconfig/ - read_only: true - command: ["solr-precreate", "test", "/solrconfig"] - - db: - image: postgres:13 - container_name: mampf_db_test - environment: - - POSTGRES_USER=mampf - - POSTGRES_DB=mampf - - POSTGRES_HOST_AUTH_METHOD=trust - - mailcatcher: - restart: on-failure:10 - image: dockage/mailcatcher:latest - - mampf: - build: - context: ./../.. - dockerfile: docker/run_tests/Dockerfile - image: mampf:tests - container_name: mampf_mampf_test - entrypoint: ./docker/run_tests/run_tests.sh - environment: - RAILS_ENV: test - TEST_DATABASE_ADAPTER: postgresql - TEST_DATABASE_DATABASE: mampf - TEST_DATABASE_INTERACTIONS: interactions - TEST_DATABASE_USERNAME: mampf - TEST_DATABASE_HOST: db - TEST_DATABASE_PORT: 5432 - MAILSERVER: mailcatcher - FROM_ADDRESS: development@localhost - URL_HOST: localhost - PROJECT_EMAIL: project@localhost - PROJECT_NOTIFICATION_EMAIL: project+notification@localhost - ERROR_EMAIL: error@localhost - INSTANCE_PATH: mampf - REDIS_URL: redis://redis:6379/1 - SOLR_HOST: solr - SOLR_PORT: 8983 - SOLR_PATH: /solr/test - volumes: - - type: bind - source: ../../app/ - target: /usr/src/app/app/ - - type: bind - source: ../../spec/ - target: /usr/src/app/spec/ - - /usr/src/app/completed_initial_run - depends_on: - - db - - solr - - redis - - mailcatcher diff --git a/docker/run_tests/run_tests.sh b/docker/run_tests/run_tests.sh deleted file mode 100755 index 20bc2a040..000000000 --- a/docker/run_tests/run_tests.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -cd /usr/src/app -if ! [ -f completed_initial_run ] -then - echo 'Initialising mampf' &> >(tee -a /usr/src/app/log/initialisation.log) - echo running: bundle exec rails db:create &> >(tee -a /usr/src/app/log/initialisation.log) - bundle exec rails db:create > /usr/src/app/log/initialisation.log - echo running: bundle exec rails db:migrate &> >(tee -a /usr/src/app/log/initialisation.log) - bundle exec rails db:migrate > /usr/src/app/log/initialisation.log - echo running: bundle exec rails assets:precompile &> >(tee -a /usr/src/app/log/initialisation.log) - bundle exec rails assets:precompile &> /usr/src/app/log/initialisation.log - bundle exec rake sunspot:solr:reindex & - echo 'finished initialisation' &> >(tee -a /usr/src/app/log/initialisation.log) - touch completed_initial_run -fi -rm -f tmp/pids/server.pid -rspec diff --git a/spec/cypress/e2e/simple_spec.cy.js b/spec/cypress/e2e/simple_spec.cy.js deleted file mode 100644 index f45101e10..000000000 --- a/spec/cypress/e2e/simple_spec.cy.js +++ /dev/null @@ -1,10 +0,0 @@ -describe('My First Test', function() { - it('visit root', function() { - - // Visit the application under test - cy.visit('/'); - - cy.contains("MaMpf"); - cy.screenshot(); - }); - }); diff --git a/spec/cypress/e2e/testing_spec.cy.js b/spec/cypress/e2e/testing_spec.cy.js deleted file mode 100644 index bd57f3fa6..000000000 --- a/spec/cypress/e2e/testing_spec.cy.js +++ /dev/null @@ -1,22 +0,0 @@ -describe("Testing", () => { - - beforeEach(() => { - cy.app("clean"); - }); - describe("Set up test environment", () => { - beforeEach(() => { - cy.app("clean"); - cy.appScenario("admin"); - cy.visit("/users/sign_in"); - cy.get('input[type="email"]').type("administrator@mampf.edu"); - cy.get('input[type="password"]').type("test123456"); - cy.get('input[type="submit"]').click(); - }); - it("can view tutorials", () => { - cy.appFactories([ - ]).then((lectures) => { - - }); - }); - }); -}); \ No newline at end of file diff --git a/spec/cypress/e2e/tutorials_spec.cy.js b/spec/cypress/e2e/tutorials_spec.cy.js index ba5ca9e94..da2213d1b 100644 --- a/spec/cypress/e2e/tutorials_spec.cy.js +++ b/spec/cypress/e2e/tutorials_spec.cy.js @@ -43,9 +43,9 @@ describe("Tutorials", () => { cy.visit(`lectures/${lectures[0].id}`); cy.contains("Tutorien").should("exist"); cy.contains("Tutorien").click(); - cy.get('.col-sm-9 > .dropdown > .btn').contains("Tutorien").should("exist"); - cy.get('.col-sm-9 > .dropdown > .btn').contains("Tutorien").click(); - cy.get('.col-sm-9 > .dropdown > .dropdown-menu > .dropdown-item').contains(lectures[2].title).click(); + cy.get('main > .dropdown > .btn').contains("Tutorien").should("exist"); + cy.get('main > .dropdown > .btn').contains("Tutorien").click(); + cy.get('main > .dropdown > .dropdown-menu > .dropdown-item').contains(lectures[2].title).click(); cy.reload(); cy.contains("Übersicht").should("exist"); }); @@ -87,9 +87,9 @@ describe("Tutorials", () => { cy.visit(`lectures/${lectures[0].id}`); cy.contains("Tutorien").should("exist"); cy.contains("Tutorien").click(); - cy.contains("Übersicht").should("exist"); - cy.contains("Übersicht").click(); - cy.get('.col-sm-9 > .dropdown > .btn').contains("Tutorien").click(); + cy.get('main').contains("Übersicht").should("exist"); + cy.get('main').contains("Übersicht").click(); + cy.get('main > .dropdown > .btn').contains("Tutorien").click(); cy.contains('Eigene Tutorien').should('exist'); cy.contains('Sonstige Tutorien').should('exist'); cy.get('.dropdown-menu').contains(lectures[2].title).should("exist"); diff --git a/spec/cypress/e2e/watchlists_spec.cy.js b/spec/cypress/e2e/watchlists_spec.cy.js index 259ca0271..f9d773671 100644 --- a/spec/cypress/e2e/watchlists_spec.cy.js +++ b/spec/cypress/e2e/watchlists_spec.cy.js @@ -88,8 +88,7 @@ describe("Watchlists", () => { ] ]).then((data) => { cy.visit('lectures/1'); - cy.get('.nav > :nth-child(6) > .nav-link').click(); - cy.get('.fa-bookmark').click(); + cy.get('#watchlistsIcon').click(); cy.get('#watchlistButton').contains(`${data[0].name}`).should('exist'); }); });