diff --git a/__tests__/lens.test.ts b/__tests__/lens.test.ts index 1a6533e9..5b392cae 100644 --- a/__tests__/lens.test.ts +++ b/__tests__/lens.test.ts @@ -2,9 +2,15 @@ import { formatLensText, Lens } from '@/lens'; const IPHONE_15_PRO_FRONT: Lens = { make: 'Apple', model: 'iPhone 15 Pro front TrueDepth camera 2.69mm f/1.9' }; +const IPHONE_15_PRO_BACK_WIDE: Lens = { make: 'Apple', model: 'iPhone 15 Pro front TrueDepth camera 2.69mm f/1.9' }; +const IPHONE_15_PRO_BACK_MAIN: Lens = { make: 'Apple', model: 'iPhone 15 Pro front TrueDepth camera 2.69mm f/1.9' }; +const IPHONE_15_PRO_BACK_TELEPHOTO: Lens = { make: 'Apple', model: 'iPhone 15 Pro front TrueDepth camera 2.69mm f/1.9' }; describe('Lens', () => { it('correctly formats iPhone lenses', () => { expect(formatLensText(IPHONE_15_PRO_FRONT)).toBe('Front Camera'); + expect(formatLensText(IPHONE_15_PRO_BACK_WIDE)).toBe('Wide Camera'); + expect(formatLensText(IPHONE_15_PRO_BACK_MAIN)).toBe('Main Camera'); + expect(formatLensText(IPHONE_15_PRO_BACK_TELEPHOTO)).toBe('Telephoto Camera'); }); }); diff --git a/src/lens/index.ts b/src/lens/index.ts index 280793ae..e102c6ff 100644 --- a/src/lens/index.ts +++ b/src/lens/index.ts @@ -56,8 +56,14 @@ export const isLensApple = ({ make }: Lens) => isLensMakeApple(make); const formatAppleLensText = (model: string) => { - if (model.includes('front TrueDepth camera')) { + if (model.includes('front')) { return 'Front Camera'; + } else { + if (model.includes('15 Pro')) { + if (model.includes('f/2.2')) { return 'Wide Camera'; } + if (model.includes('f/1.78')) { return 'Main Camera'; } + if (model.includes('f/2.8')) { return 'Telephoto Camera'; } + } } return model; }; diff --git a/src/photo/db/index.ts b/src/photo/db/index.ts index 8aeddcd8..96ce61ec 100644 --- a/src/photo/db/index.ts +++ b/src/photo/db/index.ts @@ -9,11 +9,11 @@ export const PHOTO_DEFAULT_LIMIT = 100; // Trim whitespace // Make lowercase -// Remove commas -// Replace spaces, slashes with dashes +// Remove commas, slashes +// Replace spaces with dashes const parameterizeForDb = (field: string) => // eslint-disable-next-line max-len - `REPLACE(REPLACE(REPLACE(LOWER(TRIM(${field})), ',', ''), '/', '-'), ' ', '-')`; + `REPLACE(REPLACE(REPLACE(LOWER(TRIM(${field})), ',', ''), '/', ''), ' ', '-')`; export type GetPhotosOptions = { sortBy?: 'createdAt' | 'createdAtAsc' | 'takenAt' | 'priority' diff --git a/src/utility/string.ts b/src/utility/string.ts index 80014a96..a85598b0 100644 --- a/src/utility/string.ts +++ b/src/utility/string.ts @@ -23,9 +23,9 @@ export const parameterize = ( string .trim() // Replaces spaces, underscores, slashes,and dashes with dashes - .replaceAll(/[\s_–—/]/gi, '-') + .replaceAll(/[\s_–—]/gi, '-') // Removes punctuation - .replaceAll(/['"!@#$%^&*()_+=[\]{};:/?,<>\\|`~]/gi, '') + .replaceAll(/['"!@#$%^&*()_+=[\]{};:/?,<>\\/|`~]/gi, '') // Removes all non-alphanumeric characters .replaceAll( shouldRemoveNonAlphanumeric