diff --git a/src/config.ts b/src/config.ts index d4ae8b54..4e7890d6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -108,7 +108,6 @@ export const API_DOCS = 'https://docs.igboapi.com'; export const SPEECH_TO_TEXT_API = isProduction ? 'https://speech.igboapi.com' : 'http://localhost:3333'; - export const IGBO_TO_ENGLISH_API = ENV_IGBO_TO_ENGLISH_URL; // SendGrid API export const SENDGRID_API_KEY = SENDGRID_API_KEY_SOURCE || ''; diff --git a/src/controllers/__tests__/translation.test.ts b/src/controllers/__tests__/translation.test.ts index 12db431f..54768a8f 100644 --- a/src/controllers/__tests__/translation.test.ts +++ b/src/controllers/__tests__/translation.test.ts @@ -3,7 +3,8 @@ import { requestFixture, responseFixture, nextFunctionFixture, -} from '../../../__tests__/shared/fixtures'; +} from '../../__tests__/shared/fixtures'; +import { MAIN_KEY } from '../../../__tests__/shared/constants'; import { getTranslation } from '../translation'; describe('translation', () => { @@ -15,7 +16,7 @@ describe('translation', () => { body: { igbo: 'aka' }, headers: { 'Content-Type': 'application/json', - 'X-API-Key': 'main_key', + 'X-API-Key': MAIN_KEY, }, }); const res = responseFixture(); @@ -32,7 +33,7 @@ describe('translation', () => { body: { igbo: 'aka'.repeat(100) }, headers: { 'Content-Type': 'application/json', - 'X-API-Key': 'main_key', + 'X-API-Key': MAIN_KEY, }, }); const res = responseFixture(); @@ -41,14 +42,16 @@ describe('translation', () => { data: { igbo: 'aka'.repeat(100) }, }); await getTranslation(req, res, next); - expect(next).toHaveBeenCalled(); + expect(next).toHaveBeenCalledWith( + new Error('Cannot translate text greater than 120 characters') + ); }); it('throws validation error when input string is empty', async () => { const req = requestFixture({ body: { igbo: '' }, headers: { 'Content-Type': 'application/json', - 'X-API-Key': 'main_key', + 'X-API-Key': MAIN_KEY, }, }); const res = responseFixture(); @@ -57,6 +60,6 @@ describe('translation', () => { data: { igbo: '' }, }); await getTranslation(req, res, next); - expect(next).toHaveBeenCalled(); + expect(next).toHaveBeenCalledWith(new Error('Cannot translate empty string')); }); }); diff --git a/src/middleware/helpers/authorizeDeveloperUsage.ts b/src/middleware/helpers/authorizeDeveloperUsage.ts index 6a9307e4..d7552076 100644 --- a/src/middleware/helpers/authorizeDeveloperUsage.ts +++ b/src/middleware/helpers/authorizeDeveloperUsage.ts @@ -67,6 +67,13 @@ export const authorizeDeveloperUsage = async ({ }); }; +/** + * The function maps route strings to the APIType Enum that would represent usage + * of the route + * @param route The string name of the route + * @returns The ApiType of the route passed as input. For example /speech-to-text would + * route to the Speech-to-Text API type + */ const getApiTypeFromRoute = (route: string): ApiType => { switch (route) { case ApiTypeToRoute.SPEECH_TO_TEXT: diff --git a/src/routers/routerV2.ts b/src/routers/routerV2.ts index 5d08c074..0e9c29e5 100644 --- a/src/routers/routerV2.ts +++ b/src/routers/routerV2.ts @@ -1,5 +1,4 @@ import { Router } from 'express'; -import rateLimit from 'express-rate-limit'; import { getWords, getWord } from '../controllers/words'; import { getExample, getExamples } from '../controllers/examples'; import { getNsibidiCharacter, getNsibidiCharacters } from '../controllers/nsibidi'; @@ -9,16 +8,6 @@ import validId from '../middleware/validId'; import validateApiKey from '../middleware/validateApiKey'; import analytics from '../middleware/analytics'; import attachRedisClient from '../middleware/attachRedisClient'; -import { MiddleWare } from 'src/types'; - -// TODO: add rate limiting with upstash -// const ONE_DAY = 24 * 60 * 60 * 1000; -// const REQUESTS_PER_MS_TRANSLATION = 5; - -// const translationRateLimiter: MiddleWare = rateLimit({ -// windowMs: ONE_DAY, -// max: REQUESTS_PER_MS_TRANSLATION, -// }); const routerV2 = Router();