#DTO's class not instanciated when using @Body decorator with supertest

2 messages · Page 1 of 1 (latest)

sturdy harness
#
// the test
const response = await request(app.getHttpServer())
  .post('/api/v1/parent-agencies')
  .set('Authorization', `Bearer ${token}`)
  .send({
    name: 'Parent Agency',
  });

Expected (which works when running with start:e2e)

@Post()
@UseGuards(PoliciesGuard)
@CheckPolicies((ability) => ability.can(Action.Create, ParentAgencies))
create(
  @Body() body: CreateParentAgenciesRequestBody,
): Promise<CreateParentAgenciesResponseData> {
  return this.parentAgenciesService.create(body.toModel()); // should work
}

Actual:

TypeError: body.toModel is not a function

I tried logging it both in start:dev mode and test mode and here's the difference:

// start:dev
body CreateParentAgenciesRequestBody { name: 'skibidi' }

// test
body { name: 'Parent Agency' 

How do I address this ?

#

Nevermind writing that last part acutally reminded me that I forgor to add the validation pipe 🤡