Skip to content

Commit

Permalink
Update types
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Mar 1, 2025
1 parent 2cbbc7b commit 041a314
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 252 deletions.
8 changes: 5 additions & 3 deletions backend/app/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AppsIndex(BaseModel):
description: str
id: str
type: str
translations: dict[str, dict[str, str]]
translations: dict[str, dict[str, str]] | None = None
project_license: str
is_free_license: bool
app_id: str
Expand All @@ -66,10 +66,12 @@ class AppsIndex(BaseModel):

# Custom validator to map None to the Enum 'NONE'
@field_validator("verification_method", mode="before")
def map_none_to_enum(cls, v):
def map_none_to_enum(cls, v: str | None):
if v is None:
return VerificationMethod.NONE
return

# map rest to enum - returns a keyerror
return VerificationMethod[v.upper()]


class Filter(BaseModel):
Expand Down
123 changes: 73 additions & 50 deletions frontend/src/codegen/app/app.msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,33 @@ export const getPostSearchSearchPostResponseMock = (
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => ({
id: faker.string.alpha(20),
name: faker.string.alpha(20),
summary: faker.string.alpha(20),
installs_last_month: faker.helpers.arrayElement([
faker.helpers.arrayElement([
faker.number.int({ min: undefined, max: undefined }),
null,
]),
undefined,
]),
trending: faker.helpers.arrayElement([
faker.helpers.arrayElement([
faker.number.int({ min: undefined, max: undefined }),
null,
]),
undefined,
]),
keywords: faker.helpers.arrayElement([
Array.from(
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => faker.string.alpha(20)),
null,
]),
app_id: faker.string.alpha(20),
summary: faker.string.alpha(20),
description: faker.string.alpha(20),
icon: faker.string.alpha(20),
categories: faker.helpers.arrayElement([
id: faker.string.alpha(20),
type: faker.string.alpha(20),
translations: faker.helpers.arrayElement([
faker.helpers.arrayElement([
Array.from(
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => faker.string.alpha(20)),
{
[faker.string.alphanumeric(5)]: {
[faker.string.alphanumeric(5)]: faker.string.alpha(20),
},
},
null,
]),
undefined,
]),
project_license: faker.string.alpha(20),
is_free_license: faker.datatype.boolean(),
app_id: faker.string.alpha(20),
icon: faker.string.alpha(20),
main_categories: faker.helpers.arrayElement([
faker.helpers.arrayElement(Object.values(MainCategory)),
faker.helpers.arrayElements(Object.values(MainCategory)),
Expand Down Expand Up @@ -118,6 +108,10 @@ export const getPostSearchSearchPostResponseMock = (
faker.string.alpha(20),
null,
]),
verification_login_is_organization: faker.helpers.arrayElement([
faker.string.alpha(20),
null,
]),
verification_website: faker.helpers.arrayElement([
faker.string.alpha(20),
null,
Expand All @@ -126,10 +120,31 @@ export const getPostSearchSearchPostResponseMock = (
faker.string.alpha(20),
null,
]),
verification_login_is_organization: faker.helpers.arrayElement([
faker.string.alpha(20),
runtime: faker.helpers.arrayElement([faker.string.alpha(20), null]),
updated_at: faker.number.int({ min: undefined, max: undefined }),
arches: faker.helpers.arrayElement([
Array.from(
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => faker.string.alpha(20)),
null,
]),
added_at: faker.number.int({ min: undefined, max: undefined }),
trending: faker.helpers.arrayElement([
faker.helpers.arrayElement([
faker.number.int({ min: undefined, max: undefined }),
null,
]),
undefined,
]),
installs_last_month: faker.helpers.arrayElement([
faker.helpers.arrayElement([
faker.number.int({ min: undefined, max: undefined }),
null,
]),
undefined,
]),
isMobileFriendly: faker.datatype.boolean(),
})),
query: faker.string.alpha(20),
processingTimeMs: faker.number.int({ min: undefined, max: undefined }),
Expand All @@ -144,6 +159,14 @@ export const getPostSearchSearchPostResponseMock = (
}),
},
},
facetStats: {
[faker.string.alphanumeric(5)]: {
[faker.string.alphanumeric(5)]: faker.number.int({
min: undefined,
max: undefined,
}),
},
},
...overrideResponse,
})

Expand Down Expand Up @@ -440,14 +463,37 @@ export const getGetPlatformsPlatformsGetMockHandler = (
})
}

export const getGetAddonsAddonAppIdGetMockHandler = (
overrideResponse?:
| string[]
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<string[]> | string[]),
) => {
return http.get("*/addon/:appId", async (info) => {
await delay(1000)

return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === "function"
? await overrideResponse(info)
: overrideResponse
: getGetAddonsAddonAppIdGetResponseMock(),
),
{ status: 200, headers: { "Content-Type": "application/json" } },
)
})
}

export const getGetExceptionsExceptionsGetMockHandler = (
overrideResponse?:
| unknown
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<unknown> | unknown),
) => {
return http.get("*/exceptions", async (info) => {
return http.get("*/exceptions/", async (info) => {
await delay(1000)
if (typeof overrideResponse === "function") {
await overrideResponse(info)
Expand All @@ -472,29 +518,6 @@ export const getGetExceptionsForAppExceptionsAppIdGetMockHandler = (
})
}

export const getGetAddonsAddonAppIdGetMockHandler = (
overrideResponse?:
| string[]
| ((
info: Parameters<Parameters<typeof http.get>[1]>[0],
) => Promise<string[]> | string[]),
) => {
return http.get("*/addon/:appId", async (info) => {
await delay(1000)

return new HttpResponse(
JSON.stringify(
overrideResponse !== undefined
? typeof overrideResponse === "function"
? await overrideResponse(info)
: overrideResponse
: getGetAddonsAddonAppIdGetResponseMock(),
),
{ status: 200, headers: { "Content-Type": "application/json" } },
)
})
}

export const getAddToFavoritesFavoritesAppIdAddPostMockHandler = (
overrideResponse?:
| unknown
Expand Down Expand Up @@ -584,9 +607,9 @@ export const getAppMock = () => [
getGetRuntimeListRuntimesGetMockHandler(),
getGetSummarySummaryAppIdGetMockHandler(),
getGetPlatformsPlatformsGetMockHandler(),
getGetAddonsAddonAppIdGetMockHandler(),
getGetExceptionsExceptionsGetMockHandler(),
getGetExceptionsForAppExceptionsAppIdGetMockHandler(),
getGetAddonsAddonAppIdGetMockHandler(),
getAddToFavoritesFavoritesAppIdAddPostMockHandler(),
getRemoveFromFavoritesFavoritesAppIdRemoveDeleteMockHandler(),
getGetFavoritesFavoritesGetMockHandler(),
Expand Down
Loading

0 comments on commit 041a314

Please sign in to comment.