Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e test fails with "No CLS namespace defined in your app ... please call initializeTransactionalContext()" #341

Open
topchyalexey opened this issue Dec 12, 2023 · 2 comments

Comments

@topchyalexey
Copy link

on node 16 environment

[Nest] 64242  - 12/12/2023, 12:29:00 PM   ERROR [ExceptionsHandler] No CLS namespace defined in your app ... please call initializeTransactionalContext() before application start.
Error: No CLS namespace defined in your app ... please call initializeTransactionalContext() before application start.
    at UserService.createUser (/Users/aleksey.topchy/IdeaProjects/philit/medical/aip-back/node_modules/typeorm-transactional/src/transactions/wrap-in-transaction.ts:36:13)
    at AuthController.userRegister (/Users/aleksey.topchy/IdeaProjects/philit/medical/aip-back/src/modules/auth/auth.controller.ts:32:52)
    at /Users/aleksey.topchy/IdeaProjects/philit/medical/aip-back/node_modules/@nestjs/core/router/router-execution-context.js:38:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  console.log
    query: SELECT "UserEntity"."id" AS "UserEntity_id", "UserEntity"."created_at" AS "UserEntity_created_at", "UserEntity"."updated_at" AS "UserEntity_updated_at", "UserEntity"."first_name" AS "UserEntity_first_name", "UserEntity"."last_name" AS "UserEntity_last_name", "UserEntity"."role" AS "UserEntity_role", "UserEntity"."email" AS "UserEntity_email", "UserEntity"."password" AS "UserEntity_password", "UserEntity"."phone" AS "UserEntity_phone", "UserEntity"."avatar" AS "UserEntity_avatar", (SELECT CONCAT("UserEntity".first_name, ' ', "UserEntity".last_name)) AS "UserEntity_full_name" FROM "users" "UserEntity" WHERE ("UserEntity"."email" = $1) LIMIT 1 -- PARAMETERS: ["[email protected]"]

      at Function.logInfo (../src/platform/PlatformTools.ts:232:17)

 FAIL  test/app.e2e-spec.ts (10.961 s)
  AuthController (e2e)
    ✕ /auth/register (POST) (48 ms)
    ✕ /auth/login (POST) (26 ms)
    ✕ /auth/me (GET) (4 ms)

  ● AuthController (e2e) › /auth/register (POST)
@topchyalexey
Copy link
Author

Fixed by adding

**import { initializeTransactionalContext } from 'typeorm-transactional';**

import { AppModule } from '../src/app.module';

describe('AuthController (e2e)', () => {
  let app: INestApplication;
  let accessToken: string;

  beforeAll(async () => {
    **initializeTransactionalContext();**
    const moduleFixture = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = moduleFixture.createNestApplication();
    await app.init();
  });

but then I get next error

[Nest] 65272  - 12/12/2023, 12:37:56 PM   ERROR [ExceptionsHandler] You need to use @UseDto on class (UserEntity) be able to call toDto function
Error: You need to use @UseDto on class (UserEntity) be able to call toDto function
    at UserEntity.toDto (/Users/aleksey.topchy/IdeaProjects/philit/medical/aip-back/src/common/abstract.entity.ts:24:19)
    at AuthController.userRegister (/Users/aleksey.topchy/IdeaProjects/philit/medical/aip-back/src/modules/auth/auth.controller.ts:33:28)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
  console.log
    query: SELECT "UserEntity"."id" AS "UserEntity_id", "UserEntity"."created_at" AS "UserEntity_created_at", "UserEntity"."updated_at" AS "UserEntity_updated_at", "UserEntity"."first_name" AS "UserEntity_first_name", "UserEntity"."last_name" AS "UserEntity_last_name", "UserEntity"."role" AS "UserEntity_role", "UserEntity"."email" AS "UserEntity_email", "UserEntity"."password" AS "UserEntity_password", "UserEntity"."phone" AS "UserEntity_phone", "UserEntity"."avatar" AS "UserEntity_avatar", (SELECT CONCAT("UserEntity".first_name, ' ', "UserEntity".last_name)) AS "UserEntity_full_name" FROM "users" "UserEntity" WHERE ("UserEntity"."email" = $1) LIMIT 1 -- PARAMETERS: ["[email protected]"]

      at Function.logInfo (../src/platform/PlatformTools.ts:232:17)

@topchyalexey
Copy link
Author

Fixed it by this issue workaround
#332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant