Skip to content

Commit

Permalink
chore: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ebubae committed Oct 31, 2024
1 parent 75a662a commit dd66099
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand Down
15 changes: 9 additions & 6 deletions src/controllers/__tests__/translation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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'));
});
});
7 changes: 7 additions & 0 deletions src/middleware/helpers/authorizeDeveloperUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 0 additions & 11 deletions src/routers/routerV2.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down

0 comments on commit dd66099

Please sign in to comment.