Я использую express и должен и я пытаюсь выполнить вызовы на конечные точки моего сервера (app.js) для проверки результатов.TypeError: Невозможно прочитать свойство 'post' of undefined
Мой файловый сервер (app.js):
app.post('/customer', authorize({allowedPowerLevel: 50}), function(request, response, callback) {
const customerType = parseInt(request.body.customerType);
const data = JSON.parse(request.body.data);
});
});
Crud Операции index.js файл (пост() определение):
let server = supertest.agent("http://localhost:5003");
let loggedInUserManager = require("./../loggedInUser")();
let idProvider = require("./../id-provider")();
let jsonProvider = require("./../json-provider")();
module.exports = function() {
const crudOperations = {
post: function(idCustomerType, callback) {
server
.post("/customer")
.set("x-access-token", loggedInUserManager.authentication.token)
.send({
customerType: idCustomerType,
data: JSON.stringify(jsonProvider.getTemplate("individual"))
})
.end(function(error, response) {
callback(response);
});
}
}
}
crudOperations пост() вызов
let should = require("should");
let crudCustomer = require("./crud-customer")();
let startTests = function(idCustomerType) {
describe(`Post customer`, function() {
let returnedCustomerId;
it(`should post a new customer`, function(done) {
crudCustomer.post(idCustomerType, function(response) {
should(response.status).be.eql(200);
should(response.body).have.property("customerId").not.be.eql("");
returnedCustomerId = response.body.idCustomer;
done();
});
});
});
При попытке запуска тестов я получаю следующую ошибку:
Post customer should post a new customer:
TypeError: Cannot read property 'post' of undefined
at Context.<anonymous> (C:\Users\Alex\Desktop\projects\watson\server\tests\customer.js:15:19)
at callFnAsync
Я что-то пропустил?
crud-customer имеет любой экспорт? –
№. должен ли он возвращать crudCustomer? –