> For the complete documentation index, see [llms.txt](https://book.restfulnode.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.restfulnode.com/part-3/chapter-10/6-testing-the-response.md).

# Testing the Response

Recall how we implemented the `userResponseDto`.

*File: src/responses/userResponseDto.js*

```javascript
const userResponseDto = (user) => {
  return {
    id: user['id'],
    first_name: user['first_name'],
    last_name: user['last_name'],
    email: user['email'],
    phone_number: user['phone_number']
  }
}

module.exports = userResponseDto
```

You may look at this and feel a sense of déjà vu, and you would be right, because writing a test for the `userResponseDto` is quite similar to writing a test for the `registerUserRequestDto`.

As always we'll setup our test suite as follows.

*File: src/responses/\_\_tests/userResponseDto.test.js*

```javascript
const userResponseDto = require('../userResponseDto')

describe('Test Suite: userResponseDto', () => {
  // Tests go here
})
```

### The Tests

Since this is quite an easy function to test, let's add in some more test cases this time.

```javascript
const userResponseDto = require('../userResponseDto')

describe('Test Suite: Response', () => {
  test('Correct request 1 - empty parameters', () => {
    // 1. Arrange
    const user = {}

    // 2. Act
    const response = userResponseDto(user)

    // 3. Assert
    expect(response).toEqual({})
  })

  test('Correct request 2 - extra useless parameters', () => {
    // 1. Arrange
    const user = {
      id: '123',
      first_name: 'john',
      last_name: 'doe',
      email: 'johndoe@email.com',
      phone_number: '1234567890',
      password: 'undefined',
      extraParam1: null,
      extraParam2: 'whatzup',
      body: 'John Doe is cool'
    }

    // 2. Act
    const response = userResponseDto(user)

    // 3. Assert
    expect(response).toEqual({
      id: '123',
      first_name: 'john',
      last_name: 'doe',
      email: 'johndoe@email.com',
      phone_number: '1234567890'
    })
  })

  test('Correct request 3 - add password fields, hopefully they do not show up', () => {
    // 1. Arrange
    const user = {
      id: '123',
      first_name: 'Yichen',
      last_name: 'Zhu',
      email: 'yichen@yichen.com',
      password: 'yichen-and-his-awesome-password',
      password_confirmation: 'yichen-and-his-awesome-password',
      phone_number: '1234567890'
    }

    // 2. Act
    const response = userResponseDto(user)

    // 3. Assert
    expect(response).toEqual({
      id: '123',
      first_name: 'Yichen',
      last_name: 'Zhu',
      email: 'yichen@yichen.com',
      phone_number: '1234567890'
    })
  })
})
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.restfulnode.com/part-3/chapter-10/6-testing-the-response.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
