Skip to content

Commit a3e4acd

Browse files
authored
fix(recommendations): [DIS-843] Make region optional & unvalidated (#54)
1 parent 34b87d0 commit a3e4acd

File tree

4 files changed

+5
-68
lines changed

4 files changed

+5
-68
lines changed

openapi.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,10 @@ paths:
287287
]
288288
- name: region
289289
in: query
290-
required: true
291-
description: This region string is Fx domain language, and built from Fx expectations. Parameter values are not case sensitive.
290+
required: false
291+
description: This region string is Fx domain language, and built from Fx expectations. Parameter values are not case sensitive. See [Firefox Home & New Tab Regional Differences](https://mozilla-hub.atlassian.net/wiki/spaces/FPS/pages/80448805/Regional+Differences).
292292
schema:
293293
type: string
294-
enum: [
295-
# relevant docs: https://docs.google.com/document/d/1omclr-eETJ7zAWTMI7mvvsc3_-ns2Iiho4jPEfrmZfo
296-
US, CA, DE, GB, IE, FR, ES, IT, IN, CH, AT, BE,
297-
]
298294
responses:
299295
'200':
300296
description: OK

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,12 @@ describe('input.ts recommendations query parameters', () => {
138138
parameters: 'locale',
139139
},
140140
}),
141-
expect.objectContaining<APIError>({
142-
status: '400',
143-
title: 'Bad Request',
144-
detail:
145-
'Region must be provided. Valid regions include [' +
146-
'"US","CA","DE","GB","IE","FR","ES","IT","IN","CH","AT","BE"]',
147-
source: {
148-
parameters: 'region',
149-
},
150-
}),
151141
]),
152142
})
153143
);
154144
});
155145

156-
it('region and locale are required', () => {
146+
it('locale is required', () => {
157147
const res = validate({
158148
count: 30,
159149
// region and locale are missing
@@ -175,16 +165,6 @@ describe('input.ts recommendations query parameters', () => {
175165
parameters: 'locale',
176166
},
177167
}),
178-
expect.objectContaining<APIError>({
179-
status: '400',
180-
title: 'Bad Request',
181-
detail:
182-
'Region must be provided. Valid regions include [' +
183-
'"US","CA","DE","GB","IE","FR","ES","IT","IN","CH","AT","BE"]',
184-
source: {
185-
parameters: 'region',
186-
},
187-
}),
188168
]),
189169
})
190170
);

src/api/desktop/recommendations/inputs.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,44 +78,6 @@ const isValidLocale: ValidatorFunction = (locale?: string) =>
7878
}
7979
: null;
8080

81-
// all valid regions
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-
];
96-
// copy to set for fast lookup, all lowercase
97-
const validRegionsSet = new Set(
98-
validRegions.map((region) => region.toLowerCase())
99-
);
100-
101-
// prettier config thrashes here
102-
// prettier-ignore
103-
/**
104-
* Validates regions. This ensures that region is present and
105-
* contains a valid value.
106-
*
107-
* Returns null if valid, or returns details to build an error
108-
* if invalid.
109-
* @param region
110-
*/
111-
const isValidRegion: ValidatorFunction = (region?: string) =>
112-
!validRegionsSet.has(region?.toLowerCase?.())
113-
? {
114-
propertyName: 'region',
115-
errorDetail: `Region must be provided. Valid regions include ${JSON.stringify(validRegions)}`,
116-
}
117-
: null;
118-
11981
// prettier config thrashes here
12082
// prettier-ignore
12183
// returns details to build error response if invalid
@@ -174,7 +136,6 @@ export const validate = (
174136
const errorDetails = [
175137
isValidCount(query.count),
176138
isValidLocale(query.locale),
177-
isValidRegion(query.region),
178139
].filter((ed) => ed !== null);
179140

180141
if (errorDetails.length > 0) {

src/generated/openapi/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ export interface operations {
155155
parameters: {
156156
/** @description The number of items to return. */
157157
/** @description This locale string is Fx domain language, and built from Fx expectations. Parameter values are not case sensitive. */
158-
/** @description This region string is Fx domain language, and built from Fx expectations. Parameter values are not case sensitive. */
158+
/** @description This region string is Fx domain language, and built from Fx expectations. Parameter values are not case sensitive. See [Firefox Home & New Tab Regional Differences](https://mozilla-hub.atlassian.net/wiki/spaces/FPS/pages/80448805/Regional+Differences). */
159159
query: {
160160
count?: number;
161161
locale: "fr" | "fr-FR" | "es" | "es-ES" | "it" | "it-IT" | "en" | "en-CA" | "en-GB" | "en-US" | "de" | "de-DE" | "de-AT" | "de-CH";
162-
region: "US" | "CA" | "DE" | "GB" | "IE" | "FR" | "ES" | "IT" | "IN" | "CH" | "AT" | "BE";
162+
region?: string;
163163
};
164164
};
165165
responses: {

0 commit comments

Comments
 (0)