forwardemail / forwardemail/supertest

Request field values all undefined

Open
#445 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

I have been trying to use *supertest* for testing my API calls. I have no problems passing values in parameters through requests. e.g `req.body.value`

However, in `req.params.value` all my fields are `undefined`. Am I initializing my `app` or something else wrong?

```
/* initialize controller or APIs to be called here */
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.post('/v1/accounts/:account_id/money/deposits', money.makeDeposit);
```

```
let body = {
frequency: IMMEDIATE,
amount: 100,
sourceId: active_source_id,
bankAccountNumber: active_account_number,
};
await request(app)
.post(`/v1/accounts/${account_id}/money/deposits`)
.set('Content-type', 'application/json')
.type('json')
.send(body)
.expect(200)
.then((response) => {
console.log('> resposne: ', response.body);
})
.catch((error) => {
console.log('> Your error:', error);
});
});
```

My request body:

```
Received request with body:
{ frequency: undefined,
amount: undefined,
sourceId: undefined,
bankAccountNumber: undefined,
url: '/v1/accounts/abc/money/deposits' } { account_id: 'abc' }
```

Thanks :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.