Skip to content

Commit

Permalink
chore: update sample apps (#1698)
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab authored Nov 9, 2024
1 parent 119c4d9 commit 37519ba
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ export const getListPetsResponseMock = (): Pets =>
(_, i) => i + 1,
).map(() => ({
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.word.sample(),
name: faker.string.alpha(20),
tag: faker.string.alpha(20),
}));

export const getCreatePetsResponseMock = (
overrideResponse: Partial<Pet> = {},
): Pet => ({
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.word.sample(),
name: faker.string.alpha(20),
tag: faker.string.alpha(20),
...overrideResponse,
});

export const getUpdatePetsResponseMock = (
overrideResponse: Partial<Pet> = {},
): Pet => ({
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.word.sample(),
name: faker.string.alpha(20),
tag: faker.string.alpha(20),
...overrideResponse,
});

export const getShowPetByIdResponseMock = (
overrideResponse: Partial<Pet> = {},
): Pet => ({
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.word.sample(),
name: faker.string.alpha(20),
tag: faker.string.alpha(20),
...overrideResponse,
});

Expand Down
48 changes: 24 additions & 24 deletions samples/next-app-with-fetch/app/gen/pets/pets.msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const getListPetsResponseMock = (): Pets =>
faker.helpers.arrayElement([
{
...getListPetsResponseDogMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -87,12 +87,12 @@ export const getListPetsResponseMock = (): Pets =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
{
...getListPetsResponseCatMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -106,8 +106,8 @@ export const getListPetsResponseMock = (): Pets =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
]),
);
Expand Down Expand Up @@ -173,7 +173,7 @@ export const getCreatePetsResponseMock = (): Pet =>
faker.helpers.arrayElement([
{
...getCreatePetsResponseDogMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -187,12 +187,12 @@ export const getCreatePetsResponseMock = (): Pet =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
{
...getCreatePetsResponseCatMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -206,8 +206,8 @@ export const getCreatePetsResponseMock = (): Pet =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
]);

Expand Down Expand Up @@ -272,7 +272,7 @@ export const getUpdatePetsResponseMock = (): Pet =>
faker.helpers.arrayElement([
{
...getUpdatePetsResponseDogMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -286,12 +286,12 @@ export const getUpdatePetsResponseMock = (): Pet =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
{
...getUpdatePetsResponseCatMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -305,8 +305,8 @@ export const getUpdatePetsResponseMock = (): Pet =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
]);

Expand Down Expand Up @@ -371,7 +371,7 @@ export const getShowPetByIdResponseMock = (): Pet =>
faker.helpers.arrayElement([
{
...getShowPetByIdResponseDogMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -385,12 +385,12 @@ export const getShowPetByIdResponseMock = (): Pet =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
{
...getShowPetByIdResponseCatMock(),
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
callingCode: faker.helpers.arrayElement([
faker.helpers.arrayElement(['+33', '+420', '+33'] as const),
undefined,
Expand All @@ -404,8 +404,8 @@ export const getShowPetByIdResponseMock = (): Pet =>
]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
},
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getListPetsResponseMock = (): Pets =>
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => ({
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: (() => faker.number.int({ min: 1, max: 99999 }))(),
name: (() => faker.person.lastName())(),
Expand All @@ -23,7 +23,7 @@ export const getListPetsResponseMock = (): Pets =>
export const getCreatePetsResponseMock = (
overrideResponse: Partial<Pet> = {},
): Pet => ({
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: (() => faker.person.lastName())(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ export const getListPetsResponseMock = (): Pets =>
{ length: faker.number.int({ min: 1, max: 10 }) },
(_, i) => i + 1,
).map(() => ({
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
}));

export const getCreatePetsResponseMock = (
overrideResponse: Partial<Pet> = {},
): Pet => ({
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
...overrideResponse,
});

export const getShowPetByIdResponseMock = (
overrideResponse: Partial<Pet> = {},
): Pet => ({
'@id': faker.helpers.arrayElement([faker.word.sample(), undefined]),
'@id': faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
email: faker.helpers.arrayElement([faker.internet.email(), undefined]),
id: faker.number.int({ min: undefined, max: undefined }),
name: faker.word.sample(),
tag: faker.helpers.arrayElement([faker.word.sample(), undefined]),
name: faker.string.alpha(20),
tag: faker.helpers.arrayElement([faker.string.alpha(20), undefined]),
...overrideResponse,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,14 @@ export function useListPetsSuspenseInfinite<
export const createPets = (
createPetsBody: CreatePetsBody,
version: number = 1,
signal?: AbortSignal,
) => {
return customInstance<void>({
url: `/v${version}/pets`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data: createPetsBody,
signal,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ export const useCreatePetsHook = () => {
const createPets = useCustomClient<void>();

return useCallback(
(createPetsBody: BodyType<CreatePetsBody>, version: number = 1) => {
(
createPetsBody: BodyType<CreatePetsBody>,
version: number = 1,
signal?: AbortSignal,
) => {
return createPets({
url: `/v${version}/pets`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data: createPetsBody,
signal,
});
},
[createPets],
Expand Down
Loading

0 comments on commit 37519ba

Please sign in to comment.