From 534b809789d443781e797719e2998ec31cd315c7 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 18 Oct 2023 22:25:10 -0500 Subject: [PATCH] Make redirect controller general --- __tests__/controllers/redirectController.spec.ts | 15 ++++++--------- src/controllers/redirectController.ts | 13 ++++++------- src/routes.ts | 2 -- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/__tests__/controllers/redirectController.spec.ts b/__tests__/controllers/redirectController.spec.ts index fa8c6396..48121605 100644 --- a/__tests__/controllers/redirectController.spec.ts +++ b/__tests__/controllers/redirectController.spec.ts @@ -1,5 +1,5 @@ import RedirectController from '../../src/controllers/redirectController' -import { beforeEach, describe, expect, it } from '@jest/globals' +import { beforeEach, expect, it } from '@jest/globals' import { getMockReq, getMockRes } from '@jest-mock/express' const { res, mockClear } = getMockRes() @@ -8,13 +8,10 @@ beforeEach(() => { mockClear() }) -describe('sep21', () => { - it('should return a redirect to notion', async () => { - const req = getMockReq() +it('can redirect to a given url', () => { + const req = getMockReq() + const url = 'https://example.com' - await RedirectController.sep21(req, res) - - expect(res.redirect) - .toHaveBeenCalledWith(RedirectController.sep21Url) - }) + RedirectController.redirect(req, res, url) + expect(res.redirect).toHaveBeenCalledWith(url) }) diff --git a/src/controllers/redirectController.ts b/src/controllers/redirectController.ts index 1c9716cf..178c99f0 100644 --- a/src/controllers/redirectController.ts +++ b/src/controllers/redirectController.ts @@ -1,12 +1,11 @@ import { type Request, type Response } from 'express' export default class RedirectController { - static PATHS = { - sep21: '/sep21', - } - static sep21Url = 'https://ginger-flood-c72.notion.site/The-2023-Celebration-of-Rachel-s-32nd-Birthday-Also-Known-As-Halloween-in-sepember-a17c5537f8594c30bb301a48c988f7ec' - - static async sep21 (_req: Request, res: Response): Promise { - res.redirect(RedirectController.sep21Url) + static async redirect ( + _req: Request, + res: Response, + url: string + ): Promise { + res.redirect(url) } } diff --git a/src/routes.ts b/src/routes.ts index dfbd61fd..28216821 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -8,7 +8,6 @@ import FirestoreAdapter from './data/firestore/firestoreAdapter.js' import TmdbAdapter from './data/tmdb/tmdbAdapter.js' import RsvpController from './controllers/rsvpController.js' import HealthCheckController from './controllers/healthCheckController.js' -import RedirectController from './controllers/redirectController.js' export function registerRoutes ( express: Express, @@ -62,7 +61,6 @@ function routes ( CacheController.PATHS.emailTemplates, cacheController.cacheEmailTemplates.bind(cacheController) ), - new Route(RedirectController.PATHS.sep21, RedirectController.sep21), ] }