Skip to content

Commit b38a860

Browse files
authored
feat(recommendations): [DIS-648] Add locales & regions (#52)
* feat(recommendations): [DIS-648] Add locales & regions * fix(recommendations): [DIS-648] Add regions The previous commit only expanded locales * fix: remove outdated comment * chore: add comma to end of yml list
1 parent 1cfa41a commit b38a860

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

openapi.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,14 @@ paths:
220220
type: string
221221
enum: [
222222
# relevant docs: https://docs.google.com/document/d/1omclr-eETJ7zAWTMI7mvvsc3_-ns2Iiho4jPEfrmZfo
223-
# listing locales that should still be served through the v3 APIs,
224-
# these are intentionally disabled for now.
225-
# en-CA, en-GB, en-US,
226-
# de, de-AT, de-CH,
227223

228-
# new markets will be served through this API:
224+
# fr, es, it are served through this API in Firefox 114,
225+
# and we plan to migrate all NewTab markets in Firefox 116:
229226
fr, fr-FR,
230227
es, es-ES,
231228
it, it-IT,
229+
en, en-CA, en-GB, en-US,
230+
de, de-DE, de-AT, de-CH,
232231
]
233232
- name: region
234233
in: query
@@ -238,12 +237,7 @@ paths:
238237
type: string
239238
enum: [
240239
# relevant docs: https://docs.google.com/document/d/1omclr-eETJ7zAWTMI7mvvsc3_-ns2Iiho4jPEfrmZfo
241-
# listing regions that should still be served through the v3 APIs,
242-
# these are intentionally disabled for now.
243-
# US, CA, DE, GB, IN, CH, AT, BE, IE
244-
245-
# new markets will be served through this API:
246-
FR, ES, IT,
240+
US, CA, DE, GB, IE, FR, ES, IT, IN, CH, AT, BE,
247241
]
248242
responses:
249243
'200':
@@ -319,7 +313,7 @@ paths:
319313
properties:
320314
data:
321315
type: array
322-
items:
316+
items:
323317
oneOf:
324318
- $ref: "#/components/schemas/Save"
325319
- $ref: "#/components/schemas/PendingSave"

src/api/desktop/recommendations/inputs.spec.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ import {
1212
import { APIError, APIErrorResponse, BFFFxError } from '../../../bfffxError';
1313

1414
const randomLocale = () =>
15-
faker.helpers.arrayElement(['fr', 'fr-FR', 'es', 'es-ES', 'it', 'it-IT']);
16-
17-
const randomRegion = () => faker.helpers.arrayElement(['FR', 'ES', 'IT']);
15+
faker.helpers.arrayElement([
16+
'fr',
17+
'fr-FR',
18+
'es',
19+
'es-ES',
20+
'it',
21+
'it-IT',
22+
'en',
23+
'en-CA',
24+
'de',
25+
'de-CH',
26+
]);
27+
28+
const randomRegion = () =>
29+
faker.helpers.arrayElement(['FR', 'ES', 'IT', 'DE', 'US', 'CA', 'IN']);
1830

1931
describe('input.ts recommendations query parameters', () => {
2032
describe('setDefaultsAndCoerceTypes', () => {
@@ -119,7 +131,9 @@ describe('input.ts recommendations query parameters', () => {
119131
status: '400',
120132
title: 'Bad Request',
121133
detail:
122-
'Locale must be provided. Valid locales include: ["fr","fr-FR","es","es-ES","it","it-IT"]',
134+
'Locale must be provided. Valid locales include: [' +
135+
'"fr","fr-FR","es","es-ES","it","it-IT","en","en-CA",' +
136+
'"en-GB","en-US","de","de-DE","de-AT","de-CH"]',
123137
source: {
124138
parameters: 'locale',
125139
},
@@ -128,7 +142,8 @@ describe('input.ts recommendations query parameters', () => {
128142
status: '400',
129143
title: 'Bad Request',
130144
detail:
131-
'Region must be provided. Valid regions include ["FR","ES","IT"]',
145+
'Region must be provided. Valid regions include [' +
146+
'"US","CA","DE","GB","IE","FR","ES","IT","IN","CH","AT","BE"]',
132147
source: {
133148
parameters: 'region',
134149
},
@@ -153,7 +168,9 @@ describe('input.ts recommendations query parameters', () => {
153168
status: '400',
154169
title: 'Bad Request',
155170
detail:
156-
'Locale must be provided. Valid locales include: ["fr","fr-FR","es","es-ES","it","it-IT"]',
171+
'Locale must be provided. Valid locales include: [' +
172+
'"fr","fr-FR","es","es-ES","it","it-IT","en","en-CA",' +
173+
'"en-GB","en-US","de","de-DE","de-AT","de-CH"]',
157174
source: {
158175
parameters: 'locale',
159176
},
@@ -162,7 +179,8 @@ describe('input.ts recommendations query parameters', () => {
162179
status: '400',
163180
title: 'Bad Request',
164181
detail:
165-
'Region must be provided. Valid regions include ["FR","ES","IT"]',
182+
'Region must be provided. Valid regions include [' +
183+
'"US","CA","DE","GB","IE","FR","ES","IT","IN","CH","AT","BE"]',
166184
source: {
167185
parameters: 'region',
168186
},

src/api/desktop/recommendations/inputs.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,22 @@ type ValidatorFunction = (value: any) => {
3737
};
3838

3939
// all valid locales
40-
const validLocales = ['fr', 'fr-FR', 'es', 'es-ES', 'it', 'it-IT'];
40+
const validLocales = [
41+
'fr',
42+
'fr-FR',
43+
'es',
44+
'es-ES',
45+
'it',
46+
'it-IT',
47+
'en',
48+
'en-CA',
49+
'en-GB',
50+
'en-US',
51+
'de',
52+
'de-DE',
53+
'de-AT',
54+
'de-CH',
55+
];
4156
// copy to set for fast lookup, all lowercase
4257
const validLocalesSet = new Set(
4358
validLocales.map((locale) => locale.toLowerCase())
@@ -64,7 +79,20 @@ const isValidLocale: ValidatorFunction = (locale?: string) =>
6479
: null;
6580

6681
// all valid regions
67-
const validRegions = ['FR', 'ES', 'IT'];
82+
const validRegions = [
83+
'US',
84+
'CA',
85+
'DE',
86+
'GB',
87+
'IE',
88+
'FR',
89+
'ES',
90+
'IT',
91+
'IN',
92+
'CH',
93+
'AT',
94+
'BE',
95+
];
6896
// copy to set for fast lookup, all lowercase
6997
const validRegionsSet = new Set(
7098
validRegions.map((region) => region.toLowerCase())

0 commit comments

Comments
 (0)