title: Node JS - Testing API avoid long response body tests
body: <p>I am creating API tests for my Node JS project. But a problem that I am facing is the inconvenience of testing the response body for each property. At this point I have created a <code>isValidProperty</code> method for each model. This method gets executed on when testing the response of a valid test (GET, POST and PUT/PATCH).</p>
  <p>But this can get tedious to write this for each model. Also the method below does not check if each property is the correct type. So this should also be added to the method. Another issue is that when the model changes this method needs to be updated.</p>
  <p>Is there a proper way to test if the response is correct and has the right properties with the right values filled in the right type?</p>
  <p>In my projects I use class-valditor to test the request body using DTO's. I could write a DTO-like class using class-valaditor for each model. Where the annotations of class-validator check if each property is valid.</p>
  <pre><code>const isValidProject = (project, sentProject): void =&gt; {
    expect(project).toHaveProperty('uuid')
    expect(project).toHaveProperty('createdAt')
    expect(project).toHaveProperty('updatedAt')
    expect(project).toHaveProperty('calculationType')
    expect(project).toHaveProperty('projectType')
    expect(project).toHaveProperty('street')
    expect(project).toHaveProperty('number')
    expect(project).toHaveProperty('addition')
    expect(project).toHaveProperty('zipcode')
    expect(project).toHaveProperty('city')
    expect(project).toHaveProperty('description')
    expect(project).toHaveProperty('settings')
  
    expect(project.calculationType).toBe(sentProject.calculationType)
    expect(project.projectType).toBe(sentProject.projectType)
    expect(project.street).toBe(sentProject.street)
    expect(project.number).toBe(sentProject.number)
    expect(project.addition).toBe(sentProject.addition)
    expect(project.zipcode).toBe(sentProject.zipcode)
    expect(project.city).toBe(sentProject.city)
    expect(project.description).toBe(sentProject.description)
    expect(project.settings).toEqual(sentProject.settings)
  } 
  </code></pre>