|
| 1 | +import { IocContract } from '@adonisjs/fold' |
| 2 | +import { createContext } from '../tests/context' |
| 3 | +import { createTestApp, TestContainer } from '../tests/app' |
| 4 | +import { Config } from '../config/app' |
| 5 | +import { initIocContainer } from '..' |
| 6 | +import { AppServices } from '../app' |
| 7 | +import { truncateTables } from '../tests/tableManager' |
| 8 | +import { |
| 9 | + CreateMerchantContext, |
| 10 | + MerchantRoutes, |
| 11 | + createMerchantRoutes |
| 12 | +} from './routes' |
| 13 | +import { MerchantService } from './service' |
| 14 | + |
| 15 | +describe('Merchant Routes', (): void => { |
| 16 | + let deps: IocContract<AppServices> |
| 17 | + let appContainer: TestContainer |
| 18 | + let merchantRoutes: MerchantRoutes |
| 19 | + let merchantService: MerchantService |
| 20 | + |
| 21 | + beforeAll(async (): Promise<void> => { |
| 22 | + deps = initIocContainer(Config) |
| 23 | + appContainer = await createTestApp(deps) |
| 24 | + merchantService = await deps.use('merchantService') |
| 25 | + const logger = await deps.use('logger') |
| 26 | + |
| 27 | + merchantRoutes = createMerchantRoutes({ |
| 28 | + merchantService, |
| 29 | + logger |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + afterEach(async (): Promise<void> => { |
| 34 | + await truncateTables(deps) |
| 35 | + }) |
| 36 | + |
| 37 | + afterAll(async (): Promise<void> => { |
| 38 | + await appContainer.shutdown() |
| 39 | + }) |
| 40 | + |
| 41 | + describe('create', (): void => { |
| 42 | + test('Creates a merchant', async (): Promise<void> => { |
| 43 | + const merchantData = { |
| 44 | + name: 'Test Merchant' |
| 45 | + } |
| 46 | + |
| 47 | + const ctx = createContext<CreateMerchantContext>( |
| 48 | + { |
| 49 | + headers: { |
| 50 | + Accept: 'application/json', |
| 51 | + 'Content-Type': 'application/json' |
| 52 | + } |
| 53 | + }, |
| 54 | + {} |
| 55 | + ) |
| 56 | + ctx.request.body = merchantData |
| 57 | + |
| 58 | + await merchantRoutes.create(ctx) |
| 59 | + |
| 60 | + expect(ctx.status).toBe(200) |
| 61 | + expect(ctx.response.body).toEqual({ |
| 62 | + id: expect.any(String), |
| 63 | + name: merchantData.name |
| 64 | + }) |
| 65 | + }) |
| 66 | + }) |
| 67 | +}) |
0 commit comments