diff --git a/cypress/integration/endpoint-tests.js b/cypress/integration/endpoint-tests.js index aabdb33b9db..d6d716c88b4 100644 --- a/cypress/integration/endpoint-tests.js +++ b/cypress/integration/endpoint-tests.js @@ -91,22 +91,28 @@ describe(`Visual regression testing for foundation.mozilla.org`, () => { // Opportunity page tests (single and multi-page) - it(`Single-page opportunity`, function() { - cy.visit(`/en/opportunity/single-page/`); - cy.window() - .its(`main-js:react:finished`) - .should(`equal`, true); - cy.wait(500); - cy.percySnapshot(); - }); - - it(`Multi-page opportunity`, function() { - cy.visit(`/en/opportunity/multi-page/`); - cy.window() - .its(`main-js:react:finished`) - .should(`equal`, true); - cy.wait(500); - cy.percySnapshot(); + it(`Single-page opportunity should redirect to /intiatives`, function() { + cy.request({ + url: `/en/opportunity/single-page-opportunity/`, + followRedirect: false + }).then(res => { + expect(res.status).to.eq(302); + expect(res.redirectedToUrl).to.eq( + `${Cypress.config().baseUrl}/en/initiatives/single-page-opportunity/` + ); + }); + }); + + it(`Multi-page opportunity should redirect to /intiatives`, function() { + cy.request({ + url: `/en/opportunity/multi-page-opportunity/`, + followRedirect: false + }).then(res => { + expect(res.status).to.eq(302); + expect(res.redirectedToUrl).to.eq( + `${Cypress.config().baseUrl}/en/initiatives/multi-page-opportunity/` + ); + }); }); // Campaign page tests (single and multi-page) diff --git a/network-api/networkapi/urls.py b/network-api/networkapi/urls.py index 728f5faecbc..9c29013c8ba 100644 --- a/network-api/networkapi/urls.py +++ b/network-api/networkapi/urls.py @@ -15,6 +15,7 @@ from networkapi.views import EnvVariablesView, review_app_help_view from networkapi.buyersguide import views as buyersguide_views from networkapi.wagtailpages.rss import RSSFeed, AtomFeed +from networkapi.wagtailpages.views import redirect_to_initiatives from experiments import views as experiment_views admin.autodiscover() @@ -72,6 +73,10 @@ path('blog/rss/', RSSFeed()), path('blog/atom/', AtomFeed()), + # redirect /opportunity Wagtail pages to /initiatives + # see https://github.com/mozilla/foundation.mozilla.org/issues/2971 for context + url(r'^opportunity/(?P.*)', redirect_to_initiatives), + # wagtail-managed data url(r'', include(wagtail_urls)), ) diff --git a/network-api/networkapi/wagtailpages/views.py b/network-api/networkapi/wagtailpages/views.py index 40f2ca56372..003c853c945 100644 --- a/network-api/networkapi/wagtailpages/views.py +++ b/network-api/networkapi/wagtailpages/views.py @@ -1,5 +1,6 @@ from django.http import HttpResponseNotFound -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.utils import translation def custom404_view(request, exception): @@ -22,3 +23,15 @@ def custom404_view(request, exception): else: html = render(request, '404.html') return HttpResponseNotFound(html.content) + + +def redirect_to_initiatives(request, subpath): + lang = request.LANGUAGE_CODE + translation.activate(lang) + request.session[translation.LANGUAGE_SESSION_KEY] = lang + query_string = "" + + if request.META['QUERY_STRING']: + query_string = f'?{request.META["QUERY_STRING"]}' + + return redirect(f'/{request.LANGUAGE_CODE}/initiatives/{subpath}{query_string}')