From 750b609308247ce30762dde609aa75c9d7635f2c Mon Sep 17 00:00:00 2001 From: Abhishek P Anil Date: Thu, 21 Nov 2024 11:44:58 +0530 Subject: [PATCH 1/3] fix: removed organizer performer supporter without id --- src/pages/Dashboard/AddEvent/AddEvent.jsx | 77 +++++++++++++---------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/pages/Dashboard/AddEvent/AddEvent.jsx b/src/pages/Dashboard/AddEvent/AddEvent.jsx index 144e801a4..1b25f9187 100644 --- a/src/pages/Dashboard/AddEvent/AddEvent.jsx +++ b/src/pages/Dashboard/AddEvent/AddEvent.jsx @@ -1815,18 +1815,21 @@ function AddEvent() { ) initialAddedFields = initialAddedFields?.concat(otherInformationFieldNames?.contact); if (eventData?.organizer) { - let initialOrganizers = eventData?.organizer?.map((organizer) => { - return { - disambiguatingDescription: organizer?.entity?.disambiguatingDescription, - id: organizer?.entityId, - name: organizer?.entity?.name, - type: organizer?.type, - logo: organizer?.entity?.logo, - image: organizer?.entity?.image?.find((image) => image?.isMain), - contactPoint: organizer?.entity?.contactPoint, - creator: organizer?.entity?.creator, - }; - }); + let initialOrganizers = eventData?.organizer + ?.map((organizer) => { + if (organizer?.entityId) + return { + disambiguatingDescription: organizer?.entity?.disambiguatingDescription, + id: organizer?.entityId, + name: organizer?.entity?.name, + type: organizer?.type, + logo: organizer?.entity?.logo, + image: organizer?.entity?.image?.find((image) => image?.isMain), + contactPoint: organizer?.entity?.contactPoint, + creator: organizer?.entity?.creator, + }; + }) + ?.filter((organizer) => organizer); setSelectedOrganizers( treeEntitiesOption( initialOrganizers, @@ -1838,17 +1841,20 @@ function AddEvent() { ); } if (eventData?.performer) { - let initialPerformers = eventData?.performer?.map((performer) => { - return { - disambiguatingDescription: performer?.entity?.disambiguatingDescription, - id: performer?.entityId, - name: performer?.entity?.name, - type: performer?.type, - logo: performer?.entity?.logo, - image: performer?.entity?.image?.find((image) => image?.isMain), - creator: performer?.entity?.creator, - }; - }); + let initialPerformers = eventData?.performer + ?.map((performer) => { + if (performer?.entityId) + return { + disambiguatingDescription: performer?.entity?.disambiguatingDescription, + id: performer?.entityId, + name: performer?.entity?.name, + type: performer?.type, + logo: performer?.entity?.logo, + image: performer?.entity?.image?.find((image) => image?.isMain), + creator: performer?.entity?.creator, + }; + }) + ?.filter((performer) => performer); setSelectedPerformers( treeEntitiesOption( initialPerformers, @@ -1861,17 +1867,20 @@ function AddEvent() { initialAddedFields = initialAddedFields?.concat(otherInformationFieldNames?.performerWrap); } if (eventData?.collaborators) { - let initialSupporters = eventData?.collaborators?.map((supporter) => { - return { - disambiguatingDescription: supporter?.entity?.disambiguatingDescription, - id: supporter?.entityId, - name: supporter?.entity?.name, - type: supporter?.type, - logo: supporter?.entity?.logo, - image: supporter?.entity?.image?.find((image) => image?.isMain), - creator: supporter?.entity?.creator, - }; - }); + let initialSupporters = eventData?.collaborators + ?.map((supporter) => { + if (supporter?.entityId) + return { + disambiguatingDescription: supporter?.entity?.disambiguatingDescription, + id: supporter?.entityId, + name: supporter?.entity?.name, + type: supporter?.type, + logo: supporter?.entity?.logo, + image: supporter?.entity?.image?.find((image) => image?.isMain), + creator: supporter?.entity?.creator, + }; + }) + ?.filter((supporter) => supporter); setSelectedSupporters( treeEntitiesOption( initialSupporters, From 98d9a0b68e433a8983d1aa3a6b14ce0090ddc7a0 Mon Sep 17 00:00:00 2001 From: Abhishek P Anil Date: Thu, 21 Nov 2024 11:56:02 +0530 Subject: [PATCH 2/3] refactor: optimized the map --- src/pages/Dashboard/AddEvent/AddEvent.jsx | 72 ++++++++--------------- 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/src/pages/Dashboard/AddEvent/AddEvent.jsx b/src/pages/Dashboard/AddEvent/AddEvent.jsx index 1b25f9187..cc6954deb 100644 --- a/src/pages/Dashboard/AddEvent/AddEvent.jsx +++ b/src/pages/Dashboard/AddEvent/AddEvent.jsx @@ -1657,6 +1657,24 @@ function AddEvent() { } } }; + const mapEntities = (entities) => { + return entities + ?.map((entity) => { + if (entity?.entityId) { + return { + disambiguatingDescription: entity.entity?.disambiguatingDescription, + id: entity.entityId, + name: entity.entity?.name, + type: entity.type, + logo: entity.entity?.logo, + image: entity.entity?.image?.find((image) => image?.isMain), + ...(entity.entity?.contactPoint ? { contactPoint: entity.entity.contactPoint } : {}), + creator: entity.entity?.creator, + }; + } + }) + ?.filter((mappedEntity) => mappedEntity); + }; useEffect(() => { dispatch(clearActiveFallbackFieldsInfo()); @@ -1814,22 +1832,8 @@ function AddEvent() { isDataValid(eventData?.contactPoint?.name) ) initialAddedFields = initialAddedFields?.concat(otherInformationFieldNames?.contact); - if (eventData?.organizer) { - let initialOrganizers = eventData?.organizer - ?.map((organizer) => { - if (organizer?.entityId) - return { - disambiguatingDescription: organizer?.entity?.disambiguatingDescription, - id: organizer?.entityId, - name: organizer?.entity?.name, - type: organizer?.type, - logo: organizer?.entity?.logo, - image: organizer?.entity?.image?.find((image) => image?.isMain), - contactPoint: organizer?.entity?.contactPoint, - creator: organizer?.entity?.creator, - }; - }) - ?.filter((organizer) => organizer); + if (eventData.organizer) { + const initialOrganizers = mapEntities(eventData.organizer); setSelectedOrganizers( treeEntitiesOption( initialOrganizers, @@ -1840,21 +1844,9 @@ function AddEvent() { ), ); } - if (eventData?.performer) { - let initialPerformers = eventData?.performer - ?.map((performer) => { - if (performer?.entityId) - return { - disambiguatingDescription: performer?.entity?.disambiguatingDescription, - id: performer?.entityId, - name: performer?.entity?.name, - type: performer?.type, - logo: performer?.entity?.logo, - image: performer?.entity?.image?.find((image) => image?.isMain), - creator: performer?.entity?.creator, - }; - }) - ?.filter((performer) => performer); + + if (eventData.performer) { + const initialPerformers = mapEntities(eventData.performer); setSelectedPerformers( treeEntitiesOption( initialPerformers, @@ -1866,21 +1858,9 @@ function AddEvent() { ); initialAddedFields = initialAddedFields?.concat(otherInformationFieldNames?.performerWrap); } - if (eventData?.collaborators) { - let initialSupporters = eventData?.collaborators - ?.map((supporter) => { - if (supporter?.entityId) - return { - disambiguatingDescription: supporter?.entity?.disambiguatingDescription, - id: supporter?.entityId, - name: supporter?.entity?.name, - type: supporter?.type, - logo: supporter?.entity?.logo, - image: supporter?.entity?.image?.find((image) => image?.isMain), - creator: supporter?.entity?.creator, - }; - }) - ?.filter((supporter) => supporter); + + if (eventData.collaborators) { + const initialSupporters = mapEntities(eventData.collaborators); setSelectedSupporters( treeEntitiesOption( initialSupporters, From cebe7ece2d7f979b5d096092dc39cccf33b56435 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 2 Dec 2024 13:50:22 +0530 Subject: [PATCH 3/3] Updated regression tests to run on PR to develop --- .../workflows/build-production-deploy-s3.yml | 4 - .github/workflows/build-staging-deploy-s3.yml | 17 ----- .github/workflows/run-cypress-tests.yml | 76 ++++++------------- .../trigger-cypress-tests-on-pull-request.yml | 19 +++++ 4 files changed, 43 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/trigger-cypress-tests-on-pull-request.yml diff --git a/.github/workflows/build-production-deploy-s3.yml b/.github/workflows/build-production-deploy-s3.yml index 821e3f25a..0333881b6 100644 --- a/.github/workflows/build-production-deploy-s3.yml +++ b/.github/workflows/build-production-deploy-s3.yml @@ -10,10 +10,6 @@ jobs: environment: 'production' grep: '' grepTags: '@essential' - CYPRESS_ADMIN_EN_EMAIL: ${{ vars.CYPRESS_ADMIN_EN_EMAIL }} - CYPRESS_ADMIN_FR_EMAIL: ${{ vars.CYPRESS_ADMIN_FR_EMAIL }} - CYPRESS_GUEST_EN_EMAIL: ${{ vars.CYPRESS_GUEST_EN_EMAIL }} - CYPRESS_GUEST_FR_EMAIL: ${{ vars.CYPRESS_GUEST_FR_EMAIL }} secrets: DOCKER_PAT: ${{ secrets.DOCKER_PAT }} CYPRESS_PASSWORD: ${{ secrets.CYPRESS_PASSWORD }} diff --git a/.github/workflows/build-staging-deploy-s3.yml b/.github/workflows/build-staging-deploy-s3.yml index abfe5247d..44a9562a0 100644 --- a/.github/workflows/build-staging-deploy-s3.yml +++ b/.github/workflows/build-staging-deploy-s3.yml @@ -4,24 +4,7 @@ on: branches: - develop jobs: - trigger-cypress-tests: - uses: ./.github/workflows/run-cypress-tests.yml - with: - environment: 'staging' - grep: '' - grepTags: '@general' - CYPRESS_ADMIN_EN_EMAIL: ${{ vars.CYPRESS_ADMIN_EN_EMAIL }} - CYPRESS_ADMIN_FR_EMAIL: ${{ vars.CYPRESS_ADMIN_FR_EMAIL }} - CYPRESS_GUEST_EN_EMAIL: ${{ vars.CYPRESS_GUEST_EN_EMAIL }} - CYPRESS_GUEST_FR_EMAIL: ${{ vars.CYPRESS_GUEST_FR_EMAIL }} - secrets: - DOCKER_PAT: ${{ secrets.DOCKER_PAT }} - CYPRESS_PASSWORD: ${{ secrets.CYPRESS_PASSWORD }} - S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} - S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} - build-and-deploy: - needs: trigger-cypress-tests env: AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/run-cypress-tests.yml b/.github/workflows/run-cypress-tests.yml index 85afef7ed..568710672 100644 --- a/.github/workflows/run-cypress-tests.yml +++ b/.github/workflows/run-cypress-tests.yml @@ -15,22 +15,6 @@ on: description: 'Grep tags for selecting tests' required: false default: '@essential' - CYPRESS_ADMIN_EN_EMAIL: - description: 'Admin email for English tests' - required: true - type: string - CYPRESS_ADMIN_FR_EMAIL: - description: 'Admin email for French tests' - required: true - type: string - CYPRESS_GUEST_EN_EMAIL: - description: 'Guest email for English tests' - required: true - type: string - CYPRESS_GUEST_FR_EMAIL: - description: 'Guest email for French tests' - required: true - type: string workflow_call: inputs: @@ -47,22 +31,6 @@ on: required: false type: string default: '@essential' - CYPRESS_ADMIN_EN_EMAIL: - description: 'Admin email for English tests' - required: true - type: string - CYPRESS_ADMIN_FR_EMAIL: - description: 'Admin email for French tests' - required: true - type: string - CYPRESS_GUEST_EN_EMAIL: - description: 'Guest email for English tests' - required: true - type: string - CYPRESS_GUEST_FR_EMAIL: - description: 'Guest email for French tests' - required: true - type: string secrets: DOCKER_PAT: @@ -163,23 +131,31 @@ jobs: - name: Pull cypress docker image run: docker pull ghcr.io/kmdvs/cms-cypress_regression_tests:main - - name: Write grep and grepTags to cypress.env.json + - name: Run Cypress tests run: | - mkdir -p cypress - cd cypress - mkdir -p logs screenshots videos - - echo '{ - "grep": "${{ inputs.grep }}", - "grepTags": "${{ inputs.grepTags }}" - }' > cypress.env.json - - name: Verify contents of cypress.env.json - run: | - cat cypress/cypress.env.json + grep_value="${{ inputs.grep }}" + echo "Original grep_value: '$grep_value'" + grep_value_clean=$(echo "$grep_value" | tr -d '\n\r') + echo "Cleaned grep_value: '$grep_value_clean'" - - name: Run Cypress tests - run: | + if [ -z "$grep_value_clean" ]; then + grep_value_json='""' + else + grep_value_json=$(printf '%s' "$grep_value_clean" | sed 's/"/\\"/g; s/.*/"&"/') + fi + echo "JSON grep_value: '$grep_value_json'" + + # Properly format the --env argument for Cypress + env_json="{\"grepTags\":\"${{ inputs.grepTags }}\",\"grep\":${grep_value_json}}" + echo "Formatted env JSON: $env_json" + + # Simulate the Cypress --env argument + env_arg=$(printf '%s' "$env_json") + echo "Simulated --env argument for Cypress: $env_arg" + + # Validate JSON formatting + echo "$env_json" | jq . # Validate JSON formatting base_url="http://test.footlight.app:3000/" @@ -189,10 +165,7 @@ jobs: -e DEBUG="" \ -e XDG_RUNTIME_DIR=/tmp/runtime \ -e CYPRESS_BASE_URL=$base_url \ - -e CYPRESS_ADMIN_EN_EMAIL="${{ inputs.CYPRESS_ADMIN_EN_EMAIL }}" \ - -e CYPRESS_ADMIN_FR_EMAIL="${{ inputs.CYPRESS_ADMIN_FR_EMAIL }}" \ - -e CYPRESS_GUEST_EN_EMAIL="${{ inputs.CYPRESS_GUEST_EN_EMAIL }}" \ - -e CYPRESS_GUEST_FR_EMAIL="${{ inputs.CYPRESS_GUEST_FR_EMAIL }}" \ + -e CYPRESS_PRINT_LOGS_TO_CONSOLE="never" \ -e CYPRESS_ADMIN_EN_PASSWORD=${{ secrets.CYPRESS_PASSWORD }} \ -e CYPRESS_ADMIN_FR_PASSWORD=${{ secrets.CYPRESS_PASSWORD }} \ -e CYPRESS_GUEST_EN_PASSWORD=${{ secrets.CYPRESS_PASSWORD }} \ @@ -201,9 +174,8 @@ jobs: -v ${GITHUB_WORKSPACE}/cypress/screenshots:/e2e/cypress/screenshots \ -v ${GITHUB_WORKSPACE}/cypress/videos:/e2e/cypress/videos \ -v ${GITHUB_WORKSPACE}/cypress/logs:/e2e/cypress/logs \ - -v ${GITHUB_WORKSPACE}/cypress/cypress.env.json:/e2e/cypress/cypress.env.json \ ghcr.io/kmdvs/cms-cypress_regression_tests:main \ - npx cypress run --browser firefox > ${GITHUB_WORKSPACE}/cypress/logs/debug-firefox.log 2>&1 + npx cypress run --browser firefox --env "$env_arg" - name: Upload Cypress Debug Logs uses: actions/upload-artifact@v3 diff --git a/.github/workflows/trigger-cypress-tests-on-pull-request.yml b/.github/workflows/trigger-cypress-tests-on-pull-request.yml new file mode 100644 index 000000000..25d07267c --- /dev/null +++ b/.github/workflows/trigger-cypress-tests-on-pull-request.yml @@ -0,0 +1,19 @@ +name: Run regression tests on pull request to Develop + +on: + pull_request: + branches: + - develop + +jobs: + trigger-cypress-tests: + uses: ./.github/workflows/run-cypress-tests.yml + with: + environment: 'staging' + grep: '' + grepTags: '@general' + secrets: + DOCKER_PAT: ${{ secrets.DOCKER_PAT }} + CYPRESS_PASSWORD: ${{ secrets.CYPRESS_PASSWORD }} + S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }} + S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }} \ No newline at end of file