title: Passing request body to post using super-test
body: <p>I'm testing an express server using super-test and I need to test a post call.  I assume the post should be successful and return a status of 200 but it is returning 401.  I've been told by someone that I need to pass a request body with the post but I'm unsure exactly how to do this.  </p>
  
  <p>I've attempted to use .send({name: 'aName'}) but that gives me the same 401 code.  </p>
  
  <p>Below is the app.js</p>
  
  <pre><code>require('dotenv').config();
  const express = require('express');
  const bodyParser = require('body-parser');
  const hateoasLinker = require('express-hateoas-links');
  const AValidator = require('./AValidator');
  const BValidator = require('./BValidator');
  const schema_v1 = require("./schema.json");
  const {
      logService: logger
  } = require("@utils");
  
  let aValidator = AValidator(schema_v1);
  
  let ValidatorApi = BValidator.ValidatorApi('api');
  let adminValidator = BValidator.ValidatorAdmin('admin');
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  app.use(hateoasLinker);
  
  app.post('/*/activate',admiValidator, (req, res) =&gt; {
      console.log("In Activate===============&gt;");
      res.status(200);
      res.json({
          rel: "self",
          method: "POST",
          title: 'Activate Solution',
          href: "/activate"
      });
  });
  </code></pre>
  
  <p>Here is the code for the BValidator</p>
  
  <pre><code>ValidatorAdmin = function(callType){
      return function (req,res,next){
          let authoizationHeader = req.headers['authorization'];
          try {
          Verifier.verifyPayload(authoizationHeader, callType, (verificationError) =&gt; {
              if (verificationError) {
                  res.setHeader('Content-Type', 'application/json');
                  res.status(401);
                  res.json({
                      message : "verificationError "+verificationError.message
                  });
              } else {
                  next();
              }
          });
          } catch (authorizationError) {
              res.setHeader('Content-Type', 'application/json');
              res.status(401);
              res.json({
                  message : authorizationError.message
              });
  
          }
      }
  }
  
  </code></pre>
  
  <p>Here is the app.test.js</p>
  
  <pre><code>const request = require('supertest');
  const bodyParser = require('body-parser');
  let AValidator = require('../src/AValidator');
  let BValidator = require('../src/BValidator');
  BValidator = jest.fn();
  AValidator = jest.fn();
  app = require('../src/app');
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  
  describe('Test os GET/POST calls in app.js', ()=&gt;{
  
    test('Tests activate post', (done)=&gt;{
  
      BValidator.mockReturnValue({
        ValidatorApi: (req,res,next)=&gt;{
          next();
        },
        ValidatorAdmin:(req,res,next)=&gt;{
          next();
        }
      });
  
      AValidator.mockImplementation((schema)=&gt;{
        return function (req,res,next){
          next();
        }
      });
  
  
      request(app)
        .post('/test/activate')
        .set({name:'josh'})
        .then((response)=&gt;{
          expect(response.statusCode).toBe(200);
          done();
        })
  
    })
  
  
  });
  
  So ultimately I'd like this post to resolve successfully and return a status code of 200.
  </code></pre>