Skip to content

Instantly share code, notes, and snippets.

interface BookDetailsViewModel {
title: string
is_available: boolean
}
export function getBookById(dependencies: Dependencies) {
return async (req: Request, res: Response) => {
try {
const result = await dependencies
.bookInformation(req.params.id)
export const bookstoreRoutes = (app: Express, dependencies: Dependencies) => {
app.get('/books/:id', getBookById(dependencies))
}
describe('Integration | Controller | Book information', () => {
let app: Express
let fakeDependencies: Dependencies
beforeEach(() => {
fakeDependencies = {
bookInformation: sinon.stub()
}
app = express()
bookstoreRoutes(app, fakeDependencies)
export const BookInformationCard: FunctionComponent<Props> = ({ book }) => {
return book ? <p>{ book.title }</p> : <p>No book</p>
}
describe('Integration | Component | Book information Card', () => {
it('Matches to snapshot with a book', async () => {
const book = new BookDetails('title', true)
const { asFragment } = render(<BookInformationCard book={ book }/>)
await waitFor(() => {
expect(asFragment()).toMatchSnapshot()
})
})
describe('Integration | Sequelize customer loader, () => {
const CUSTOMER_ID = 'id'
let customerLoader: CustomerLoader
beforeEach(async () => {
await SequelizeCustomerModel.create({ id: CUSTOMER_ID, name: 'name', email: 'email', phone: 'phone' })
customerLoader = new SequelizeCustomerLoader()
})
describe('Integration | Gateways | Http basket repository', () => {
const BASE_API_URL = 'https://www.fakeapi.com'
let httpClient: HTTPClient
let basketRepository: BasketRepository
let basket: Basket
beforeEach(() => {
httpClient = {
get : sinon.stub(),
post: sinon.stub()
export class SequelizeCustomerLoader implements CustomerLoader {
async get(id: string): Promise<Customer> {
const customers = await SequelizeCustomerModel
.findAll({
where: { id: id },
limit: 1
})
.then(this.mapToCustomers)
return customers[0] || Promise.reject(new CustomerNotFoundError())
}
describe('Integration | Gateways | Sequelize customer loader', () => {
const CUSTOMER_ID = 'id'
let customerLoader: CustomerLoader
beforeEach(async () => {
await SequelizeCustomerModel.create({
id : CUSTOMER_ID,
name : 'name',
email: 'email',
phone: 'phone'
interface BasketBody {
basket_items: string[]
}
interface BasketResponse {
basket_items: string[]
}
export class HTTPBasketRepository implements BasketRepository {
private endpoint = 'https://www.fakeapi.com/baskets'