From db95dd7ffec2aac8ef948757673644c8b18dbd57 Mon Sep 17 00:00:00 2001 From: Joshua Graber Date: Wed, 11 Dec 2024 06:38:10 -0500 Subject: [PATCH] chore: make dormant for now --- .github/workflows/daily_integration.yml | 12 ++- src/config.ts | 2 - src/index.ts | 11 +-- src/routes/donor-box/controllers.ts | 8 -- src/routes/donor-box/test.integration.ts | 1 + src/test/find-available-port.ts | 41 -------- src/test/setup.ts | 29 ------ src/test/types.ts | 119 ----------------------- 8 files changed, 11 insertions(+), 212 deletions(-) delete mode 100644 src/test/find-available-port.ts delete mode 100644 src/test/setup.ts delete mode 100644 src/test/types.ts diff --git a/.github/workflows/daily_integration.yml b/.github/workflows/daily_integration.yml index e44acfa..3f40ab0 100644 --- a/.github/workflows/daily_integration.yml +++ b/.github/workflows/daily_integration.yml @@ -1,8 +1,12 @@ name: Daily API Integration Tests -on: - schedule: - # Runs at 00:00 EST (05:00 UTC) - - cron: '0 5 * * *' + +# Turning off daily scheduled run for now +# on: +# schedule: +# # Runs at 00:00 EST (05:00 UTC) +# - cron: '0 5 * * *' + +on: workflow_dispatch jobs: api-tests: diff --git a/src/config.ts b/src/config.ts index c64dbe4..11b6d7c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,6 +10,4 @@ const config = { // HOST: process.env.HOST || 'localhost', }; -console.log('config', config); - export default config; diff --git a/src/index.ts b/src/index.ts index 7a7f51a..d11d17c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,21 +20,14 @@ import healthRouter from './routes/health'; const app = express(); const port = config.PORT; -app.set('trust proxy', 1); -app.use(express.urlencoded({ extended: true })); +// app.set('trust proxy', 1); +// app.use(express.urlencoded({ extended: true })); app.use(rateLimiter); app.use(cors(corsOptions)); app.use(express.json()); app.use(addRequestId); app.use(requestLogger); -// Test routes -// @ts-expect-error foo -app.get('/x-forwarded-for', (request, response) => - response.send(request.headers['x-forwarded-for']) -); -// @ts-expect-error foo -app.get('/ip', (request, response) => response.send(request.ip)); // Routes app.use('/health', healthRouter); app.use('/donor-box', donorBoxRouter); diff --git a/src/routes/donor-box/controllers.ts b/src/routes/donor-box/controllers.ts index 7d5562d..a099b67 100644 --- a/src/routes/donor-box/controllers.ts +++ b/src/routes/donor-box/controllers.ts @@ -1,7 +1,6 @@ import { NextFunction, Request, Response } from 'express'; import config from '../../config'; import axios from 'axios'; -import { logger } from '../../middleware/logger'; export async function get(req: Request, res: Response, next: NextFunction) { try { @@ -22,15 +21,8 @@ export async function get(req: Request, res: Response, next: NextFunction) { }, params: req.query, // Pass through any query parameters }); - logger.info({ - response, - env: response.config.env, - header: `Basic ${btoa(`${authKey}:${authValue}`)}`, - }); res.json(response.data); } catch (error) { - logger.error(error); - console.error(error); next(error); } } diff --git a/src/routes/donor-box/test.integration.ts b/src/routes/donor-box/test.integration.ts index 2bb0934..db03a21 100644 --- a/src/routes/donor-box/test.integration.ts +++ b/src/routes/donor-box/test.integration.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import express from 'express'; import serverRoutes from './routes'; import request from 'supertest'; diff --git a/src/test/find-available-port.ts b/src/test/find-available-port.ts deleted file mode 100644 index d79b6a4..0000000 --- a/src/test/find-available-port.ts +++ /dev/null @@ -1,41 +0,0 @@ -// import { createServer } from 'net'; - -// export default function findAvailablePort(startPort = 3000): Promise { -// return new Promise((resolve, reject) => { -// const server = createServer(); - -// server.on('error', (err: NodeJS.ErrnoException) => { -// if (err.code === 'EADDRINUSE') { -// // Port is in use, try the next one -// server.close(() => { -// resolve(findAvailablePort(startPort + 1)); -// }); -// } else { -// reject(err); -// } -// }); - -// server.listen(startPort, () => { -// const { port } = server.address() as { port: number }; -// server.close(() => { -// resolve(port); -// }); -// }); -// }); -// } - -import { execSync } from 'child_process'; - -export default function findAvailablePortSync(startPort = 3000, endPort = 65535): number { - for (let port = startPort; port <= endPort; port++) { - try { - // Try to bind to the port using netstat - execSync(`lsof -i:${port}`, { stdio: 'ignore' }); - } catch { - // If the command fails, the port is available - return port; - } - } - - throw new Error('No available ports found'); -} diff --git a/src/test/setup.ts b/src/test/setup.ts deleted file mode 100644 index 95edefd..0000000 --- a/src/test/setup.ts +++ /dev/null @@ -1,29 +0,0 @@ -import supertest from 'supertest'; -import app from '../index'; // adjust path as needed -import TestAgent from 'supertest/lib/agent'; -import findAvailablePortSync from './find-available-port'; - -export let server: any; -export let request: TestAgent; - -beforeAll((done) => { - server = app.listen(findAvailablePortSync()); // Let OS assign port - request = supertest(server); - done(); -}); - -afterAll((done) => { - if (server) { - // Close all existing connections first - server.closeAllConnections(); - // Then close the server - server.close((err: any) => { - if (err) { - console.error('Error closing server:', err); - } - done(); - }); - } else { - done(); - } -}); diff --git a/src/test/types.ts b/src/test/types.ts deleted file mode 100644 index 098b49b..0000000 --- a/src/test/types.ts +++ /dev/null @@ -1,119 +0,0 @@ -export class DonationsResponse { - campaign: object; // Consider creating a Campaign type/class - donor: object; // Consider creating a Donor type/class - amount: string; - formatted_amount: string; - converted_amount: string; - formatted_converted_amount: string; - converted_net_amount: string; - formatted_converted_net_amount: string; - net_amount: string; - net_amount_currency: string; - formatted_net_amount: string; - recurring: boolean; - first_recurring_donation: boolean; - amount_refunded: string; - formatted_amount_refunded: string; - stripe_charge_id: string; - internal_notes: string | null; - membership_tier: string | null; - id: number; - status: string; - donation_type: string; - donation_date: string; - anonymous_donation: boolean; - gift_aid: boolean; - designation: string | null; - join_mailing_list: boolean; - comment: string | null; - donating_company: string | null; - currency: string; - converted_currency: string; - offline: boolean; - utm_campaign: string | null; - utm_source: string | null; - utm_medium: string | null; - utm_term: string | null; - utm_content: string | null; - address: string; - address_line_2: string; - city: string; - state: string; - zip_code: string; - country: string; - phone: string | null; - employer: string | null; - occupation: string | null; - processing_fee: number; - formatted_processing_fee: string; - fee_covered: boolean; - cover_fee_amount: number; - formatted_cover_fee_amount: string; - app_fee: number; - formatted_app_fee: string; - converted_app_fee: number; - formatted_converted_app_fee: string; - questions: any[]; - plan_id: number; - interval: string; - - constructor(data: Partial = {}) { - this.campaign = data.campaign ?? {}; - this.donor = data.donor ?? {}; - this.amount = data.amount ?? '0'; - this.formatted_amount = data.formatted_amount ?? '$0'; - this.converted_amount = data.converted_amount ?? '0'; - this.formatted_converted_amount = data.formatted_converted_amount ?? '$0'; - this.converted_net_amount = data.converted_net_amount ?? '0'; - this.formatted_converted_net_amount = data.formatted_converted_net_amount ?? '$0'; - this.net_amount = data.net_amount ?? '0'; - this.net_amount_currency = data.net_amount_currency ?? 'USD'; - this.formatted_net_amount = data.formatted_net_amount ?? '$0'; - this.recurring = data.recurring ?? false; - this.first_recurring_donation = data.first_recurring_donation ?? false; - this.amount_refunded = data.amount_refunded ?? '0.0'; - this.formatted_amount_refunded = data.formatted_amount_refunded ?? ''; - this.stripe_charge_id = data.stripe_charge_id ?? ''; - this.internal_notes = data.internal_notes ?? null; - this.membership_tier = data.membership_tier ?? null; - this.id = data.id ?? 0; - this.status = data.status ?? ''; - this.donation_type = data.donation_type ?? ''; - this.donation_date = data.donation_date ?? ''; - this.anonymous_donation = data.anonymous_donation ?? false; - this.gift_aid = data.gift_aid ?? false; - this.designation = data.designation ?? null; - this.join_mailing_list = data.join_mailing_list ?? false; - this.comment = data.comment ?? null; - this.donating_company = data.donating_company ?? null; - this.currency = data.currency ?? 'USD'; - this.converted_currency = data.converted_currency ?? 'USD'; - this.offline = data.offline ?? false; - this.utm_campaign = data.utm_campaign ?? null; - this.utm_source = data.utm_source ?? null; - this.utm_medium = data.utm_medium ?? null; - this.utm_term = data.utm_term ?? null; - this.utm_content = data.utm_content ?? null; - this.address = data.address ?? ''; - this.address_line_2 = data.address_line_2 ?? ''; - this.city = data.city ?? ''; - this.state = data.state ?? ''; - this.zip_code = data.zip_code ?? ''; - this.country = data.country ?? ''; - this.phone = data.phone ?? null; - this.employer = data.employer ?? null; - this.occupation = data.occupation ?? null; - this.processing_fee = data.processing_fee ?? 0; - this.formatted_processing_fee = data.formatted_processing_fee ?? '$0'; - this.fee_covered = data.fee_covered ?? false; - this.cover_fee_amount = data.cover_fee_amount ?? 0; - this.formatted_cover_fee_amount = data.formatted_cover_fee_amount ?? '$0'; - this.app_fee = data.app_fee ?? 0; - this.formatted_app_fee = data.formatted_app_fee ?? '$0'; - this.converted_app_fee = data.converted_app_fee ?? 0; - this.formatted_converted_app_fee = data.formatted_converted_app_fee ?? '$0'; - this.questions = data.questions ?? []; - this.plan_id = data.plan_id ?? 0; - this.interval = data.interval ?? ''; - } -}