import request from 'supertest'; import httpStatus from 'http-status'; import { ms } from '../../server'; require('../../../tests/mocks/msw/index'); /** * trial.controller.test.ts * * @module trial.controller.test.ts */ describe('trial.controller', () => { describe('getSharableLink', () => { it('should return 400 when user_id is empty', async () => { const input = { user_id: '', course_slug: 'test', }; const res = await request(ms.app).post('/api/v1/trial/link').send(input); expect((res as any).statusCode).toEqual(httpStatus.BAD_REQUEST); }); it('should return 400 when course_slug is empty', async () => { const input = { user_id: '5d5c4e40ee0453001c4541da', course_slug: '', }; const res = await request(ms.app).post('/api/v1/trial/link').send(input); expect((res as any).statusCode).toEqual(httpStatus.BAD_REQUEST); }); it('should return 200 when course_slug and user_id is filled', async () => { const input = { user_id: '5d5c4e40ee0453001c4541da', course_slug: 'test', }; const res = await request(ms.app).post('/api/v1/trial/link').send(input); expect((res as any).statusCode).toEqual(httpStatus.OK); const responseBody = JSON.parse(res.text); expect(responseBody).toMatchSnapshot(); }); it('when getSubscription return an error, getSharableLink should return 0 usage', async () => { const input = { user_id: '5d5cc441dacurso_com_erro', course_slug: 'curso_com_erro', }; const res = await request(ms.app).post('/api/v1/trial/link').send(input); const responseBody = JSON.parse(res.text); expect(responseBody.usage).toBe(0); }); }); });