I am testing CRUD
API-Operations (https://api.sap.com/api/OP_API_MAINTNOTIFICATION/overview?ReleaseInfo=2021%20FPS02), with mochajs
and chai
.
let chai = require("chai");
let chaiHttp = require("chai-http");
//Assertion Style
chai.should();
chai.use(chaiHttp);
describe("API TEST", function () {
it.only('Get all notifications', function (done) {
const url = "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification";
/**/
chai.request(url)
.post('/auth/sign_in')
// send user login details
.send({
'user': 'ExampleEmail',
'password': 'ExamplePassword'
})
.end(function (err, res) {
var token = res.body.token;
console.log(token);
done();
});
chai.request(url)
.get('')
.set("Authorization", "Bearer " + token)
.end(function (err, res) {
done();
});
});
});
Issue
In order to test the GET
function it is required for the user to authorize oneself
{"fault":{"faultstring":"Failed to resolve API Key variable request.header.apikey","detail":{"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}
- I did the authorization in this manner / gotten the token but it doesn't work yet(the token is empty), as well as the path "/auth/sign_in" seemingly isn't working
Questions
- How to do the
Authorization
for anAPI
inmochajs
in order to test saidAPI
?