Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,14 @@ paths:
type: string
enum: [
# relevant docs: https://docs.google.com/document/d/1omclr-eETJ7zAWTMI7mvvsc3_-ns2Iiho4jPEfrmZfo
# listing locales that should still be served through the v3 APIs,
# these are intentionally disabled for now.
# en-CA, en-GB, en-US,
# de, de-AT, de-CH,

# new markets will be served through this API:
# fr, es, it are served through this API in Firefox 114,
# and we plan to migrate all NewTab markets in Firefox 116:
fr, fr-FR,
es, es-ES,
it, it-IT,
en, en-CA, en-GB, en-US,
de, de-DE, de-AT, de-CH,
]
- name: region
in: query
Expand All @@ -238,12 +237,7 @@ paths:
type: string
enum: [
# relevant docs: https://docs.google.com/document/d/1omclr-eETJ7zAWTMI7mvvsc3_-ns2Iiho4jPEfrmZfo
# listing regions that should still be served through the v3 APIs,
# these are intentionally disabled for now.
# US, CA, DE, GB, IN, CH, AT, BE, IE

# new markets will be served through this API:
FR, ES, IT,
US, CA, DE, GB, IE, FR, ES, IT, IN, CH, AT, BE,
]
responses:
'200':
Expand Down Expand Up @@ -319,7 +313,7 @@ paths:
properties:
data:
type: array
items:
items:
oneOf:
- $ref: "#/components/schemas/Save"
- $ref: "#/components/schemas/PendingSave"
Expand Down
32 changes: 25 additions & 7 deletions src/api/desktop/recommendations/inputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ import {
import { APIError, APIErrorResponse, BFFFxError } from '../../../bfffxError';

const randomLocale = () =>
faker.helpers.arrayElement(['fr', 'fr-FR', 'es', 'es-ES', 'it', 'it-IT']);

const randomRegion = () => faker.helpers.arrayElement(['FR', 'ES', 'IT']);
faker.helpers.arrayElement([
'fr',
'fr-FR',
'es',
'es-ES',
'it',
'it-IT',
'en',
'en-CA',
'de',
'de-CH',
]);

const randomRegion = () =>
faker.helpers.arrayElement(['FR', 'ES', 'IT', 'DE', 'US', 'CA', 'IN']);

describe('input.ts recommendations query parameters', () => {
describe('setDefaultsAndCoerceTypes', () => {
Expand Down Expand Up @@ -119,7 +131,9 @@ describe('input.ts recommendations query parameters', () => {
status: '400',
title: 'Bad Request',
detail:
'Locale must be provided. Valid locales include: ["fr","fr-FR","es","es-ES","it","it-IT"]',
'Locale must be provided. Valid locales include: [' +
'"fr","fr-FR","es","es-ES","it","it-IT","en","en-CA",' +
'"en-GB","en-US","de","de-DE","de-AT","de-CH"]',
source: {
parameters: 'locale',
},
Expand All @@ -128,7 +142,8 @@ describe('input.ts recommendations query parameters', () => {
status: '400',
title: 'Bad Request',
detail:
'Region must be provided. Valid regions include ["FR","ES","IT"]',
'Region must be provided. Valid regions include [' +
'"US","CA","DE","GB","IE","FR","ES","IT","IN","CH","AT","BE"]',
source: {
parameters: 'region',
},
Expand All @@ -153,7 +168,9 @@ describe('input.ts recommendations query parameters', () => {
status: '400',
title: 'Bad Request',
detail:
'Locale must be provided. Valid locales include: ["fr","fr-FR","es","es-ES","it","it-IT"]',
'Locale must be provided. Valid locales include: [' +
'"fr","fr-FR","es","es-ES","it","it-IT","en","en-CA",' +
'"en-GB","en-US","de","de-DE","de-AT","de-CH"]',
source: {
parameters: 'locale',
},
Expand All @@ -162,7 +179,8 @@ describe('input.ts recommendations query parameters', () => {
status: '400',
title: 'Bad Request',
detail:
'Region must be provided. Valid regions include ["FR","ES","IT"]',
'Region must be provided. Valid regions include [' +
'"US","CA","DE","GB","IE","FR","ES","IT","IN","CH","AT","BE"]',
source: {
parameters: 'region',
},
Expand Down
32 changes: 30 additions & 2 deletions src/api/desktop/recommendations/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ type ValidatorFunction = (value: any) => {
};

// all valid locales
const validLocales = ['fr', 'fr-FR', 'es', 'es-ES', 'it', 'it-IT'];
const validLocales = [
'fr',
'fr-FR',
'es',
'es-ES',
'it',
'it-IT',
'en',
'en-CA',
'en-GB',
'en-US',
'de',
'de-DE',
'de-AT',
'de-CH',
];
// copy to set for fast lookup, all lowercase
const validLocalesSet = new Set(
validLocales.map((locale) => locale.toLowerCase())
Expand All @@ -64,7 +79,20 @@ const isValidLocale: ValidatorFunction = (locale?: string) =>
: null;

// all valid regions
const validRegions = ['FR', 'ES', 'IT'];
const validRegions = [
'US',
'CA',
'DE',
'GB',
'IE',
'FR',
'ES',
'IT',
'IN',
'CH',
'AT',
'BE',
];
// copy to set for fast lookup, all lowercase
const validRegionsSet = new Set(
validRegions.map((region) => region.toLowerCase())
Expand Down