lundi 6 mai 2019

AssertionError: expected { status: 'SUCCESS', data: [] } to equal { Object (status, data) }

I am running unit test for API call that is serving post request. I am passing request body and must get back response as account data. But I am getting only assertion error

Note: The data is fetched from Azure

spec.js

const accounts=require('./accounts');
const should=require('chai').should();
const chai=require('chai');
const chaiAsPromised=require('chai-as-promised');

chai.use(chaiAsPromised);
chai.should();

....

 beforeEach(function()
 {
    mockResponse=
    [
      {
         "AccountId": "xyz",
         "AccountState": "Active"
      }     
    ]

     it('Should get account from Azure API', function() {
      return accounts.getActivatedAccounts(req.body.customerNumber).
      should.eventually.equal(mockResponse); 

    });  
**JavascriptFile**

function getActivatedAccounts(accounts) {
 let promise = new Promise(function(resolve, reject) {
 fetch(Url , { headers: config.headersAPIM})

 .then(response => response.json())
 .then(accounts => {
  if (accounts) {
        Accounts[accounts] = [];
        for (account in accounts) {
        let accountType = accounts[account]['type]'];
        Accounts[email].push(accounts[account]);

       }

       let reply = {
          status : "SUCCESS",
          data : Accounts[accounts]
        }
        resolve(reply);  
      } else {
        let reply = {
          status : "SUCCESS",
          data : accounts
        }
        resolve(reply);     
      }
    })

    .catch(err => {
      console.log("Error: Could not find accounts");
      console.log('Error:' + err);
      let reply = {
        status:"FAILURE", 
        err: "Error: Could not find accounts. " + err
      }
      resolve(reply);
    })
  });
  return promise;
}


I am not able to give javascript file that is calling the service, I will give it in the answer section

Aucun commentaire:

Enregistrer un commentaire