<commit_before>require('../handler-base')();

// Things that proxyquire will use.

var eventStore = {
    queryStatePartitionById: sinon.stub()
  },
  instanceFormatAsHal = sinon.stub(),
  validateUUID = sinon.stub();

var handler = proxyquire('../../api/instances/instanceGet', {
  './instanceFormatAsHal': instanceFormatAsHal,
  '../helpers/eventStoreClient': eventStore,
  '../validateUUID': validateUUID
});

function createRequest() {
  var request = httpMocks.createRequest({
      method: 'GET',
      url: '/api/instances/fakeId',
      params: {
        instanceId: 'fakeId'
      }
    });
  request.href = sinon.spy();
  return request;
}

function createResponse() {
  var response = httpMocks.createResponse();
  // Set up default mocks
  response.hal = sinon.spy();
  return response;
}

describe('instanceGet', function() {

  describe('when getting an instance with a valid instanceId it', function() {
    var instance = {},
        formattedInstance = {},
        request,
        response;    

    before(function() {
      eventStore.queryStatePartitionById.resolves(instance);
      instanceFormatAsHal.returns(formattedInstance);
      request = createRequest();
      response = createResponse();

      handler(request, response);
    });

    it('should call validateUUID with correct args', function() {
      validateUUID.should.have.been.calledWith('instance', request.params.instanceId);
    });

    it('should call eventStore.queryStatePartitionById with correct args', function() {
      var args = { 
        name: 'instance',
        id: request.params.instanceId
      };
      eventStore.queryStatePartitionById.should.have.been.calledWith(args);
    });

    it('should call instanceFormatAsHal with correct args', function() {<commit_msg>More spies for instance tests.<commit_after>require('../handler-base')();

// Things that proxyquire will use.

var eventStore = {
    queryStatePartitionById: sinon.stub()
  },
  instanceFormatAsHal = sinon.stub(),
  validateUUID = sinon.stub();

var handler = proxyquire('../../api/instances/instanceGet', {
  './instanceFormatAsHal': instanceFormatAsHal,
  '../helpers/eventStoreClient': eventStore,
  '../validateUUID': validateUUID
});

function createRequest() {
  var request = httpMocks.createRequest({
    method: 'GET',
    url: '/api/instances/fakeId',
    params: {
      instanceId: 'fakeId'
    }
  });
  request.href = sinon.spy();
  return request;
}

function createResponse() {
  var response = httpMocks.createResponse();
  // Set up default mocks
  response.hal = sinon.spy();
  return response;
}

describe('instanceGet', function() {

  describe('when getting an instance with a valid instanceId it', function() {
    var instance = sinon.spy(),
      formattedInstance = sinon.spy(),
      request,
      response;

    before(function() {
      eventStore.queryStatePartitionById.resolves(instance);
      instanceFormatAsHal.returns(formattedInstance);
      request = createRequest();
      response = createResponse();

      handler(request, response);
    });

    it('should call validateUUID with correct args', function() {
      validateUUID.should.have.been.calledWith('instance', request.params.instanceId);
    });

    it('should call eventStore.queryStatePartitionById with correct args', function() {
      var args = {
        name: 'instance',
        id: request.params.instanceId
      };
      eventStore.queryStatePartitionById.should.have.been.calledWith(args);
    });

    it('should call instanceFormatAsHal with correct args', function() {
{'fraction_non_alphanumeric': 0.1332024677509815, 'fraction_numerical': 0.0, 'mean_word_length': 3.4091470951792338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4433472', 'n_tokens_mistral': 1004, 'n_tokens_neox': 1007, 'n_words': 222}