Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
feat(surface): removing validator on the surface ids (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock authored Jul 15, 2024
1 parent 77fb7e0 commit dfa8c6a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 53 deletions.
10 changes: 0 additions & 10 deletions src/routes/scheduledItems.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ describe('/scheduled-items/:scheduledSurfaceID?date=date&apikey=apikey', () => {
expect(response.statusCode).equals(404);
});

it('should return 500 if incorrect scheduled surface is provided ', async () => {
const response = await requestAgent.get(
`/scheduled-items/NEW_TAB_DOES_NOT_EXIST`,
);

expect(response.statusCode).equals(500);
expect(response.body.error).to.not.be.undefined;
expect(response.body.error).to.equal('Not a valid Scheduled Surface.');
});

it('should return 500 if incorrect date format is provided ', async () => {
const response = await requestAgent.get(
`/scheduled-items/${testNewTab}?date=20220524`,
Expand Down
8 changes: 1 addition & 7 deletions src/routes/scheduledItems.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { BrazeContentProxyResponse, TransformedCorpusItem } from './types';
import { ClientApiResponse } from '../graphql/types';
import {
getResizedImageUrl,
validateApiKey,
validateDate,
validateScheduledSurfaceGuid,
} from '../utils';
import { getResizedImageUrl, validateApiKey, validateDate } from '../utils';
import { getScheduledSurfaceStories } from '../graphql/client-api-proxy';
import config from '../config';
import { Router } from 'express';
Expand All @@ -29,7 +24,6 @@ router.get('/:scheduledSurfaceID', async (req, res, next) => {

try {
// Validate inputs
validateScheduledSurfaceGuid(scheduledSurfaceID);
validateDate(date);
await validateApiKey(apiKey);

Expand Down
27 changes: 1 addition & 26 deletions src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
import config from './config';
import {
validateDate,
validateScheduledSurfaceGuid,
validateApiKey,
getResizedImageUrl,
} from './utils';

describe('function validateScheduledSurfaceGuid', () => {
it('Allows a valid Pocket Hits surface', () => {
expect(() => {
validateScheduledSurfaceGuid('POCKET_HITS_EN_US');
}).not.toThrow();
});

it('Disallows an empty string', () => {
expect(() => {
validateScheduledSurfaceGuid('');
}).toThrowError('Not a valid Scheduled Surface');
});

it('Disallows an invalid surface GUID', () => {
expect(() => {
validateScheduledSurfaceGuid('MADE_UP_GUID_GOES_HERE');
}).toThrowError('Not a valid Scheduled Surface.');
});
});
import { validateDate, validateApiKey, getResizedImageUrl } from './utils';

describe('function validateDate', () => {
it('Allows a date in YYYY-MM-DD format', () => {
Expand Down
10 changes: 0 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
*/
import config from './config';

export function validateScheduledSurfaceGuid(name: string): void {
const allowlist = ['POCKET_HITS_EN_US', 'POCKET_HITS_DE_DE'];

if (allowlist.includes(name)) {
return;
} else {
throw new Error('Not a valid Scheduled Surface.');
}
}

/**
* Check if the date string provided is in YYYY-MM-DD format.
*
Expand Down

0 comments on commit dfa8c6a

Please sign in to comment.