I am writing test case for api where i have passed params and main file method is calling http request to get the data, So core() is basically calling the api and getting the response. this is just backend code that we have to test using jasemine.
1- First how to see response in test case if thats matched with success that is defined in test.
2- What is correct way to write test in below scenario.
balance.spec.ts
import {GetAccountBalance} from "./GetAccountBalance.node";
import {Promise} from "es6-promise";
import {HttpRequest} from "../../../core/http/HttpRequest.node";
import * as sinon from "sinon";
import {getValidationError} from "../../../common/ValidationErrorFactory";
// for easy mocking and cleanup
const sandbox = sinon.createSandbox();
afterAll(function afterTests() {
sandbox.restore();
});
describe("getAccountBalance", () => {
// the module under test
const module = new GetAccountBalance();
const testURL = 'https://essdd.max.com:4535';
const urlPath = '/webServices/instrument/accountBalance';
const fullURL = testURL + urlPath;
const options = {isJSON: true};
let result;
const stubbedEC = sandbox.spy(getValidationError);
const stubbedHttp = sandbox.createStubInstance(HttpRequest);
const success = {
"header": {
"serviceName": "accountBalance",
"statusCode": "0000",
"statusDesc": "SUCCESS"
},
"response": {
"balanceAccount": "6346.44"
}
};
const params = {Id: "21544", appName: "instrucn", channelName: "Web"};
describe("core() is called with correct params", function() {
beforeEach(() => {
result = module.core(params, stubbedHttp);
});
it("it should return the response from server", function() {
// Invoke the unit being tested as necessary
result.then((data) => {
expect(data).toBe(success);
});
});
});
});
getaccountBalnce.ts
public core(args: IAccountBalanceParam, httpRequest: HttpRequestBase): Promise<any> {
console.log('enter core');
const DBPLurl: string = this.constructDBPLurl(args);
const DBPLrequest: IAccountBalanceDBPLParam = this.constructDBPLrequest(args);
return Promise.resolve(httpRequest.makeRequest(DBPLurl, DBPLrequest, {isJSON: true}));
}
Aucun commentaire:
Enregistrer un commentaire