Reputation: 1409
I have trouble with rawbody webhook requests in my testinstance. In my normal instance which I setup with the following it works fine:
const app = await NestFactory.create(AppModule, {
logger: logger,
rawBody: true
});
In system test I setup my test instance like this
const testingModule: TestingModule = await Test.createTestingModule({
imports: [AppModule],
})
.compile();
const app = testingModule.createNestApplication({ rawBody: true });
and in my controller:
public async webhook(@Req() req: RawBodyRequest, ...
the req.rawBody is undefined and thus validation fails. i checked and rawBody is indeed a valiud parameter of createNestApplication. So I wonder what I may be missing...
Or could this have sth. to do with supertest I use for testing (https://github.com/ladjs/supertest/issues/675 suggests that may be in issue in supertest but also indicates usage of express middleware settings may prevent it). Does anybody know how I can test properly if this is a nest.js or supertest issue?
Thanks Tom
Upvotes: 3
Views: 510
Reputation: 1
One possibility: There are some extra steps to take if you have set other JSON body parser parameters like changing the limit. See this comment for details on how to address it: Access raw body of Stripe webhook in Nest.js
Upvotes: 0