const should = require('should');
const sinon = require('sinon');
require('should-sinon');

const proxyquire = require('proxyquire');
const httpMocks = require('node-mocks-http');

// Mock Service
const mockObj = {
    getAllUsers() {
        return Promise.resolve(['item 1', 'item 2']);
    }
};

const userController = proxyquire('../../app/controllers/user-controller', {
    '../services/user-service': mockObj
});

describe('User controller tests', function () {
    it('should not fail and send a JSON parsed data', async function () {
        // Given

        const res = httpMocks.createResponse();
        const req = httpMocks.createRequest({
            method: 'GET',
            url: '/user/',
            params: {}
        });

        // When
        await userController.getAllUsers(req, res);


        // Then
        res._isEndCalled().should.be.true();
        res._isJSON().should.be.true();
        res._getData().should.be.equal('["item 1","item 2"]');
    });

    it('should fail correctly if there is a problem in service', async function () {
        // Given

        const res = httpMocks.createResponse();
        const req = httpMocks.createRequest({
            method: 'GET',
            url: '/user/',
            params: {}
        });

        const serviceStub = sinon.stub(mockObj, 'getAllUsers');
        serviceStub.throws();

        // When
        await userController.getAllUsers(req, res);

        // Then
        res._isEndCalled().should.be.true();
        res.statusCode.should.be.equal(500);

        serviceStub.restore();
    });
});


@@ -983,606 +983,8 @@
  %7D);
-%0A%0A    it('should fail correctly if there is a problem in service', async function () %7B%0A        // Given%0A%0A        const res = httpMocks.createResponse();%0A        const req = httpMocks.createRequest(%7B%0A            method: 'GET',%0A            url: '/user/',%0A            params: %7B%7D%0A        %7D);%0A%0A        const serviceStub = sinon.stub(mockObj, 'getAllUsers');%0A        serviceStub.throws();%0A%0A        // When%0A        await userController.getAllUsers(req, res);%0A%0A        // Then%0A        res._isEndCalled().should.be.true();%0A        res.statusCode.should.be.equal(500);%0A%0A        serviceStub.restore();%0A    %7D);
 %0A%7D);

Remove test for fail case (handled by express)