Documentation or official way to e2e test with Crud?
See original GitHub issueIâm unable to functionally test my app with Crud.
Assuming the following functional test file:
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersService } from '../src/app/users/users.service';
import { UsersModule } from '../src/app/users/users.module';
import { Users } from '../src/app/users/users.entity';
import { config } from '../src/app/config';
import { Repository } from 'typeorm';
import { MailService } from '../src/app/services/mail/mail.service';
import { PassportModule, AuthGuard } from '@nestjs/passport';
describe('Users', () => {
let app: INestApplication;
const usersService = { findAll: () => ['test'] };
let repository: Repository<Users>;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot({
...config.database,
synchronize: true,
}),
PassportModule.register({ defaultStrategy: 'jwt', session: false }),
UsersModule
],
})
.overrideProvider(UsersService)
.useValue(usersService)
.overrideProvider(MailService)
.useValue({ sendResetPassword: () => true })
.overrideGuard(AuthGuard('jwt'))
.useValue({ canActivate: () => true })
.compile();
app = moduleRef.createNestApplication();
repository = moduleRef.get('UsersRepository');
const connection = repository.manager.connection;
// dropBeforeSync: If set to true then it drops the database with all its tables and data
await connection.synchronize(true);
await app.init();
});
it(`/GET users`, async () => {
return await request(app.getHttpServer())
.get('/users')
.expect(200)
.expect({
data: usersService.findAll(),
});
});
afterAll(async () => {
await app.close();
});
});
It returns me the following error message:
FAIL e2e/users.e2e-spec.ts (75.291s)
Users
â /GET users (298ms)
â Users âș /GET users
expected 200 "OK", got 500 "Internal Server Error"
at Test.Object.<anonymous>.Test._assertStatus (../node_modules/supertest/lib/test.js:268:12)
at Test.Object.<anonymous>.Test._assertFunction (../node_modules/supertest/lib/test.js:283:11)
at Test.Object.<anonymous>.Test.assert (../node_modules/supertest/lib/test.js:173:18)
at Server.localAssert (../node_modules/supertest/lib/test.js:131:12)
console.log src/app/common/middlewares/logger.middleware.ts:12
Wed Apr 15 2020 12:55:45 GMT+0000 (Coordinated Universal Time) - [Request] - {}
[Nest] 1279 - 04/15/2020, 12:55:45 PM [ExceptionHandler] this.service.getMany is not a function
TypeError: this.service.getMany is not a function
at UsersController.getManyBase (/usr/src/app/node_modules/@nestjsx/crud/src/crud/crud-routes.factory.ts:203:27)
at UsersController.getMany (/usr/src/app/src/app/users/users.controller.ts:118:28)
at /usr/src/app/node_modules/@nestjs/core/router/router-execution-context.js:37:29
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 75.655s, estimated 89s
Ran all test suites.
My users.controller.ts file looks like:
...
@Override('getManyBase')
@Roles('admin')
async getMany(@ParsedRequest() req: CrudRequest) {
return await this.base.getManyBase(req);
}
...
So is there any documentation (if so, I donât find it) or an âofficial wayâ to run e2e tests while using nestjsx/crud
?
I thought about overriding the controllerâs getMany()
method, but before I thought there was another âcleanâ way to do this, since I would like to query my test database as in dev/prod env.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Write CRUD E2E tests with Angular and Cypress
First Test Case: Login. In this section, I'm going to show you how to write our first cypress test to check the login...
Read more >REST API E2E Test Automation for CRUD Operations - YouTube
... CHANNEL: https://bit.ly/2YGU6JM In this SoapUI Tutorial we will learn how to automate REST API end-to-end test case for CRUD operations.
Read more >Easy E2E tests for CRUD apps with puppeteer-tools - Medium
In this article we will see how to test a supposed Client form which contains only basic information (name and email).
Read more >REST API E2E Test Automation for CRUD Operations
In this SoapUI Tutorial we will learn how to automate REST API end-to-end test case for CRUD operations. This is part 2 of...
Read more >REST API E2E Test Automation for CRUD Operations
In this SoapUI Tutorial, we will learn how to automate the REST API end-to-end test case for CRUD operations. This is part 2...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nope, that was that! Thank you for all itâs awesome! đ
P.S.: I donât know if itâs already done or not, but this example e2e test file should be linked in the doc, itâs so awesome and simple to understand itâs self-sufficient and doesnât require more explanations about how to do e2e tests with
@nestjsx/crud
. đđhave you set alwaysPaginate to true?