Record the fastfycookie module in nestjs tests

Asked

Viewed 13 times

0

Good morning, I am using nestjs to develop an api, Nest is already integrated with jest, I need to register the fastfycookie module in the test module as well as it is registered in Mains.ts

test.spects.

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

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

        app = moduleFixture.createNestApplication();

        await app.init();
    });

    it('Cadastrar usuário com sucesso /auth/register (POST)', () => {
        return request(app.getHttpServer())
            .post('/auth/register')
            .send(createTestCustomer())
            .then((response) => {
                expect(response.status).toBe(201);
                expect(response.body).toHaveProperty('token');
            });
    });
}

main.js

    const addHelmetInstance = (app: NestFastifyApplication) => {
        app.register(helmet, {
            contentSecurityPolicy: {
                reportOnly: true,
            },
        });
    };

    const bootstrap = async () => {
        const app = await NestFactory.create<NestFastifyApplication>(
            AppModule,
            new FastifyAdapter({ logger: MyAppConfig.MyApp.logging }),
        );
        const globalPrefix = 'myapp';
        app.setGlobalPrefix(globalPrefix);
        app.enableCors();
        app.register(fastifyCookies, {
            secret: 'PrivateConfig.MyApp.cookieSecret',
        });
        const port = MyAppConfig.MyApp.port || 3333;

        addHelmetInstance(app);
        await app.listen(port, () => {
            Logger.log('Listening at ' + 'PublicConfig.MyAppHost');
        });
    };

bootstrap();
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.