From 61e827f57286578eb3140e9424048af3b0e39c67 Mon Sep 17 00:00:00 2001 From: Eric BREHAULT Date: Fri, 30 Aug 2024 17:07:46 +0200 Subject: [PATCH] new dev env (#105) * new dev env * fix NUA test --- .github/workflows/run-e2e-dev.yml | 58 +++++++++++++++++++ .gitignore | 1 + cypress/e2e/0-user/auth.cy.js | 35 ++++++----- .../e2e/2-nua/create-key-with-dashboard.cy.js | 8 ++- cypress/e2e/2-nua/push-to-api.cy.js | 40 ------------- cypress/support/common.js | 44 ++++++++++++-- 6 files changed, 123 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/run-e2e-dev.yml delete mode 100644 cypress/e2e/2-nua/push-to-api.cy.js diff --git a/.github/workflows/run-e2e-dev.yml b/.github/workflows/run-e2e-dev.yml new file mode 100644 index 0000000..80b79c4 --- /dev/null +++ b/.github/workflows/run-e2e-dev.yml @@ -0,0 +1,58 @@ +name: run-e2e-dev +run-name: Running Cypress e2e tests on Dev +on: + workflow_dispatch: + branches: + - main +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true +jobs: + cypress-run: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + # Launch NucliaDB in docker + - run: | + docker pull nuclia/nucliadb:latest + docker build -t nucliadb-server . + docker run -p 8080:8080 \ + -v nucliadb-standalone:/data \ + -e NUCLIA_PUBLIC_URL="https://{zone}.gcp-global-dev-1.nuclia.io" \ + -e NUA_API_KEY=${{ secrets.NUA_KEY_DEV }} \ + nucliadb-server & + # Install npm dependencies, cache them correctly and run all Cypress tests + - name: Cypress run + id: cypress + uses: cypress-io/github-action@v6 + with: + install-command: yarn install + env: + CYPRESS_BASE_URL: https://gcp-global-dev-1.nuclia.io + CYPRESS_BEARER_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN_DEV }} + CYPRESS_NUA_KEY: ${{ secrets.NUA_KEY_DEV }} + CYPRESS_USER_NAME: ${{ secrets.USER_NAME_DEV }} + CYPRESS_USER_PWD: ${{ secrets.USER_PWD_DEV }} + CYPRESS_RUNNING_ENV: dev + # after the test run completes store reports and any screenshots + - name: Cypress reports + id: report + uses: actions/upload-artifact@v4 + if: ${{ failure() && steps.cypress.conclusion == 'failure' }} + with: + name: cypress-reports + path: cypress/reports + if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` + - name: Slack notification + id: slack + uses: slackapi/slack-github-action@v1.25.0 + if: ${{ failure() && steps.cypress.conclusion == 'failure' && github.ref_name == 'main' }} + with: + payload: | + { + "text": "⚠️ Cypress E2E failed on Dev\nTriggered by ${{ github.triggering_actor }} \nRun #${{ github.run_number }}: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\nCypress report: ${{ steps.report.outputs.artifact-url }}" + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_HOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/.gitignore b/.gitignore index 19da11c..b6e64cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # env variables cypress.env.json +cypress.env.*.json /cypress-prod.env.json # output diff --git a/cypress/e2e/0-user/auth.cy.js b/cypress/e2e/0-user/auth.cy.js index 8aacbf8..cba058d 100644 --- a/cypress/e2e/0-user/auth.cy.js +++ b/cypress/e2e/0-user/auth.cy.js @@ -3,16 +3,15 @@ import { ACCOUNT, user } from '../../support/common'; describe('User Login', () => { - it('should redirect unauthenticated user to login page', function() { + it('should redirect unauthenticated user to login page', function () { cy.visit('/at/testing'); cy.location('pathname').should('equal', '/user/login'); }); - it('should redirect to kb selection page after login', () => { cy.visit('/'); - cy.get(`[formcontrolname="email"] input`).type(user.email,{ log: false }); - cy.get(`[data-cy="password"] input[type="password"]`).type(user.password,{ log: false }); + cy.get(`[formcontrolname="email"] input`).type(user.email, { log: false }); + cy.get(`[data-cy="password"] input[type="password"]`).type(user.password, { log: false }); cy.get(`button[type='submit']`).click(); cy.location('pathname').should('equal', `/select/${ACCOUNT.slug}`); }); @@ -20,11 +19,11 @@ describe('User Login', () => { it('should allow a visitor to login and logout', () => { const permanentKb = ACCOUNT.availableZones[0].permanentKb; cy.visit('/'); - cy.get(`[formcontrolname="email"] input`).type(user.email,{ log: false }); - cy.get(`[data-cy="password"] input[type="password"]`).type(`${user.password}{enter}`,{ log: false }); - cy.get('a').contains(permanentKb.name).click(); + cy.get(`[formcontrolname="email"] input`).type(user.email, { log: false }); + cy.get(`[data-cy="password"] input[type="password"]`).type(`${user.password}{enter}`, { log: false }); + cy.get('.select-kb-list a').contains(permanentKb.name).click(); cy.location('pathname').should('equal', `/at/${ACCOUNT.slug}/${permanentKb.zone}/${permanentKb.slug}`); - cy.get(`.kb-details .title-xxs`).should('contain', 'NucliaDB API endpoint') + cy.get(`.kb-details .title-xxs`).should('contain', 'NucliaDB API endpoint'); // logout cy.get('[data-cy="user-menu"]').click(); @@ -42,18 +41,22 @@ describe('User Login', () => { cy.get(`button[type='submit']`).should('be.disabled'); }); - + it('should error for an invalid user', () => { cy.visit('/'); - cy.get(`[formcontrolname="email"] input`).type('wrong-email@gmail.com',{ log: false }); - cy.get(`[data-cy="password"] input[type="password"]`).type('invalid{enter}',{ log: false }); - cy.get(`[data-cy="login-error"]`).should('contain', 'Authentication error.').and('contain', 'Please try again or reset your password below.') + cy.get(`[formcontrolname="email"] input`).type('wrong-email@gmail.com', { log: false }); + cy.get(`[data-cy="password"] input[type="password"]`).type('invalid{enter}', { log: false }); + cy.get(`[data-cy="login-error"]`) + .should('contain', 'Authentication error.') + .and('contain', 'Please try again or reset your password below.'); }); it('should error for an invalid password for existing user', () => { cy.visit('/'); - cy.get(`[formcontrolname="email"] input`).type(user.email,{ log: false }); - cy.get(`[data-cy="password"] input[type="password"]`).type('invalid{enter}',{ log: false }); - cy.get(`[data-cy="login-error"]`).should('contain', 'Authentication error.').and('contain', 'Please try again or reset your password below.') + cy.get(`[formcontrolname="email"] input`).type(user.email, { log: false }); + cy.get(`[data-cy="password"] input[type="password"]`).type('invalid{enter}', { log: false }); + cy.get(`[data-cy="login-error"]`) + .should('contain', 'Authentication error.') + .and('contain', 'Please try again or reset your password below.'); }); -}); \ No newline at end of file +}); diff --git a/cypress/e2e/2-nua/create-key-with-dashboard.cy.js b/cypress/e2e/2-nua/create-key-with-dashboard.cy.js index c228529..1c364ba 100644 --- a/cypress/e2e/2-nua/create-key-with-dashboard.cy.js +++ b/cypress/e2e/2-nua/create-key-with-dashboard.cy.js @@ -37,9 +37,11 @@ describe('Create NUA key with the dashboard', () => { cy.get('[data-cy="open-create-nua-key-dialog"]').click(); cy.get('pa-modal-advanced').should('be.visible'); cy.get('pa-modal-advanced input[name="title"]').should('be.visible').type('A new key'); - cy.get('[formcontrolname="zone"] .pa-field-container').should('not.have.class', 'pa-readonly'); - cy.get('[formcontrolname="zone"]').click(); - cy.get('[formcontrolname="zone"] pa-option').contains(zone.title).click(); + if (ACCOUNT.hasMultipleZones) { + cy.get('[formcontrolname="zone"] .pa-field-container').should('not.have.class', 'pa-readonly'); + cy.get('[formcontrolname="zone"]').click(); + cy.get('[formcontrolname="zone"] pa-option').contains(zone.title).click(); + } cy.get('pa-modal-advanced').get('[data-cy="save-nua-client"]').click(); cy.get('pa-modal-dialog').get('[data-cy="copy-token"]').click(); cy.get('pa-modal-dialog').get('[data-cy="close-token-dialog"]').click(); diff --git a/cypress/e2e/2-nua/push-to-api.cy.js b/cypress/e2e/2-nua/push-to-api.cy.js deleted file mode 100644 index a49d5fa..0000000 --- a/cypress/e2e/2-nua/push-to-api.cy.js +++ /dev/null @@ -1,40 +0,0 @@ -/// -import { ACCOUNT } from '../../support/common'; - -describe('Push file', () => { - it('pushes a file to NUA queue', () => { - ACCOUNT.availableZones.forEach((zone) => { - cy.fixture('nuclia-logo.png') - .then((file) => - cy.request({ - method: 'POST', - url: `https://${zone.slug}.${ACCOUNT.domain}/api/v1/processing/upload`, - headers: { 'x-nuclia-nuakey': `Bearer ${zone.nuaKey}`, md5: 'fa7bfc3072bf547b3d3f5c75050adadf' }, - body: file, - }), - ) - .then((resp) => { - expect(resp.status).to.eq(200); - return cy.request({ - method: 'POST', - json: true, - url: `https://${zone.slug}.${ACCOUNT.domain}/api/v1/processing/push`, - headers: { 'x-nuclia-nuakey': `Bearer ${zone.nuaKey}` }, - body: { - filefield: { 'nuclia-logo.png': resp.body }, - }, - }); - }); - }); - }); - - it('pulls results', () => { - ACCOUNT.availableZones.forEach((zone) => { - cy.request({ - method: 'GET', - url: `https://${zone.slug}.${ACCOUNT.domain}/api/v1/processing/pull`, - headers: { 'x-stf-nuakey': `Bearer ${zone.nuaKey}` }, - }).then((res) => expect(res.status).to.eq(200)); - }); - }); -}); diff --git a/cypress/support/common.js b/cypress/support/common.js index b126a9e..cba0bb7 100644 --- a/cypress/support/common.js +++ b/cypress/support/common.js @@ -3,6 +3,7 @@ import { closeButton, nucliaSearchResultsSelector, viewerSelector } from '../e2e const ZONES = { europe: 'europe-1', usa: 'aws-us-east-2-1', + dev: 'gcp-dev-1', }; export const STANDALONE_KB_NAME = `${Cypress.env('STANDALONE_KB_NAME')}`; @@ -14,11 +15,11 @@ export const ACCOUNT_STAGE = { id: '23d9209a-34be-4648-8ef0-5b522f9976be', slug: 'testing', domain: 'stashify.cloud', + hasMultipleZones: true, availableZones: [ { slug: ZONES['europe'], title: 'Europe', - nuaKey: `${Cypress.env('NUA_KEY')}`, permanentKb: { name: 'permanent', slug: 'permanent', @@ -44,11 +45,11 @@ export const ACCOUNT_PROD = { id: '5cec111b-ea23-4b0c-a82a-d1a666dd1fd2', slug: 'nuclia-testing', domain: 'nuclia.cloud', + hasMultipleZones: true, availableZones: [ { slug: ZONES['europe'], title: 'Europe', - nuaKey: `${Cypress.env('NUA_KEY_EUROPE')}`, permanentKb: { name: 'permanent', slug: 'permanent', @@ -69,7 +70,6 @@ export const ACCOUNT_PROD = { { slug: ZONES['usa'], title: 'USA', - nuaKey: `${Cypress.env('NUA_KEY_USA')}`, permanentKb: { name: 'permanent USA', slug: 'permanent-usa', @@ -91,7 +91,43 @@ export const ACCOUNT_PROD = { permanentKbCount: 4, }; -export const ACCOUNT = `${Cypress.env('RUNNING_ENV')}` === 'prod' ? ACCOUNT_PROD : ACCOUNT_STAGE; +export const ACCOUNT_DEV = { + //eric+e2e@nuclia.com + id: '22e77dea-3552-45ad-b387-1c8755f9c3cc', + slug: 'testing', + domain: 'gcp-global-dev-1.nuclia.io', + hasMultipleZones: false, + availableZones: [ + { + slug: ZONES['dev'], + title: 'Regional gcp-dev-1', + permanentKb: { + name: 'permanent', + slug: 'permanent', + id: '0d773aed-bfb8-4228-a9d7-ed9f0ff171eb', + zone: ZONES['dev'], + }, + emptyKb: { + name: 'permanent-empty', + slug: 'permanent-empty', + id: '065ce433-e294-494c-9dc7-56c7230dbf16', + zone: ZONES['dev'], + }, + askUrl: 'https://nuclia.github.io/frontend/e2e/dev/ask.html', + citationsUrl: 'https://nuclia.github.io/frontend/e2e/dev/citations.html', + findUrl: 'https://nuclia.github.io/frontend/e2e/dev/find.html', + searchUrl: 'https://nuclia.github.io/frontend/e2e/dev/search.html', + }, + ], + permanentKbCount: 2, +}; + +export const ACCOUNT = + `${Cypress.env('RUNNING_ENV')}` === 'prod' + ? ACCOUNT_PROD + : `${Cypress.env('RUNNING_ENV')}` === 'dev' + ? ACCOUNT_DEV + : ACCOUNT_STAGE; export const user = { email: `${Cypress.env('USER_NAME')}`,