This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const UserDTOFactory = new FixtureFactory<UserDTO>(() => { | |
const { profile, ...user } = UserFactory.buildSync(); | |
return { | |
...user, | |
...profile, | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { UserDTOFactory } from '@shared/factories/User.dto.factory'; | |
import { render } from '@testing-library/react'; | |
import UserProfile from '@frontend/pages/user-profile'; | |
describe('UserProfile', () => { | |
it('matches snapshot', () => { | |
const user = UserDTOFactory.fixtureSync( | |
__dirname + '/UserProfile.spec.json', | |
) | |
const { container } = render(<UserProfile user={user} /> ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { UserDTO } from '@shared/dto/user.dto'; | |
import axios, { AxiosInstance } from 'axios'; | |
class BackendClient { | |
private instance: AxiosInstance; | |
constructor() { | |
this.instance = axios.create({ | |
baseURL: process.env.BACKEND_API_URL, | |
headers: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
getUser = async (id: string): Promise<UserDTO> => { | |
const { data } = await UserDTOFactory.build({ id }); | |
return data; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Meta } from '@storybook/react'; | |
import { UserDTO } from '@shared/dto/User.dto'; | |
import { UserDTOFactory } from '@shared/factories/User.dto.factory'; | |
import React from 'react'; | |
import UserProfile from '@frontend/pages/user-profile'; | |
export default { | |
title: 'Users/Profile', | |
component: UserProfile, | |
} as Meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from 'react'; | |
export function useInterval( | |
callback: (clearInterval: () => void) => any, | |
delay: number | null, | |
): () => void { | |
const idRef = useRef<null | number>(null); | |
const clearInterval = () => { | |
if (idRef.current) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.9-slim AS install | |
RUN apt-get update \ | |
&& apt-get upgrade -y \ | |
&& apt-get install -y --no-install-recommends curl \ | |
&& apt-get autoremove -y | |
RUN pip install --upgrade pip | |
WORKDIR /app/ | |
# install poetry and keep the get-poetry script so it can be reused later. | |
ENV POETRY_HOME="/opt/poetry" | |
RUN curl https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py > get-poetry.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import islice | |
from typing import Iterator, Sequence, TypeVar | |
T = TypeVar("T") | |
def chunk(sequence: Sequence[T], size: int) -> Iterator[list[T]]: | |
"""given a sequence, return an iterator of lists of the given size""" | |
return iter(lambda: list(islice(iter(sequence), size)), []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any | |
def is_duck(value: Any) -> bool: | |
try: | |
value.quack() | |
return True | |
except (Attribute, ValueError): | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isDuck(value) { | |
return !!( | |
value && | |
typeof value === 'object' && | |
typeof Reflect.get(value, 'quack') === 'function' | |
); | |
} |