title: E2E testing with JWT guard
body: <p>I’m trying to get e2e testing to work for this user update function. When user logs in their id and email are saved into JWT token and stored in HttpOnly Cookie. My problem is how to get this token so that it passes through JWT guard, gets id from JWT token and updates correct user. Because currently i'm obviously getting <code>Unauthorized</code> message.</p>
  <p><strong>user.2e2-spec.ts</strong></p>
  <pre><code>const mockUser: UpdateUserDto = {
    email: 'updateEmail@gmail.com',
    first_name: 'first_name1',
    last_name: 'last_name1',
    password: 'password1',
  };
  
  const mockLoginUser: LoginUserDto = {
    email: 'email@gmail.com',
    password: 'password',
  };
  
  describe('Auth controller (e2e)', () =&gt; {
    let app: INestApplication;
  
    beforeAll(async () =&gt; {
      const moduleFixture: TestingModule = await Test.createTestingModule({
        imports: [AppModule],
      }).compile();
  
      app = moduleFixture.createNestApplication();
      await app.init();
    });
  
    it('should update user info', async () =&gt; {
      const loginRes = await request(app.getHttpServer())
        .post('/login')
        .send(mockLoginUser);
  
      const data = await request(app.getHttpServer())
        .put('/me/update')
        .send(mockUser)
        .expect('success');
    });
  
    afterAll(async () =&gt; {
      await app.close();
    });
  });
  </code></pre>
  <p><strong>user.controller.ts</strong></p>
  <pre><code>  @UseGuards(jwtAuthGuard)
    @Put('me/update')
    async updateUser(@Req() request, @Body() updateUser: UpdateUserDto) {
      const data = await this.userService.updateUser(request.user.id, updateUser);
      return data;
    }
  </code></pre>
  <p><strong>jwt.strategy.ts</strong></p>
  <pre><code>@Injectable()
  export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
    constructor() {
      super({
        jwtFromRequest: (req) =&gt; {
          var token = null;
          if (req &amp;&amp; req.cookies) {
            token = req.cookies['jwt'];
          }
          return token;
        },
        ignoreExpiration: false,
        secretOrKey: process.env.ACCESS_SECRET,
      });
    }
  
    async validate(payload: any) {
      return {
        id: payload.id,
        email: payload.email,
      };
    }
  }
  </code></pre>