{"size": 1733, "ext": "js", "max_stars_repo_path": "test/unit/db/environment-reader.spec.js", "max_stars_repo_name": "WealthWizardsEngineering/version-service", "max_stars_repo_stars_event_min_datetime": "2018-07-25T09:35:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-25T09:35:54.000Z", "max_issues_repo_path": "test/unit/db/environment-reader.spec.js", "max_issues_repo_name": "WealthWizardsEngineering/version-service", "max_issues_repo_issues_event_min_datetime": "2020-08-24T10:48:52.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-24T10:48:52.000Z", "max_forks_repo_path": "test/unit/db/environment-reader.spec.js", "max_forks_repo_name": "WealthWizardsEngineering/version-service", "max_forks_repo_forks_event_min_datetime": "2019-02-20T15:51:16.000Z", "max_forks_repo_forks_event_max_datetime": "2019-02-20T15:51:16.000Z"}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 27.5079365079, "max_line_length": 140, "alphanum_fraction": 0.6607039815}
const test = require('tape');
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();

test('getEnvironments', t => {

  t.test('should pass query and projection ', assert => {

    assert.plan(2);

    const execSpy = sinon.spy();
    const distinctStub = sinon.stub().withArgs('environment').returns({ exec: execSpy });
    const findStub = sinon.stub().returns({ distinct: distinctStub });

    const applicationVersionStub = {
      find: findStub,
    };

    const { getEnvironments } = proxyquire('../../../src/db/environment-reader', { './application-version-model': applicationVersionStub });
    const target = getEnvironments;

    target();

    assert.true(execSpy.calledWithExactly());
    assert.true(execSpy.calledOnce);

  });

});

test('getEnvironment', t => {

  t.test('should find by id', assert => {

    assert.plan(2);

    const fakeId = 'fake id';

    const fakeQuery = 'fake query';
    const fakeProjection = 'fake projection';

    const thenSpy = sinon.spy()
    const execSpy = sinon.stub().returns({ then: thenSpy });
    const distinctStub = sinon.stub().withArgs('application_name').returns({ exec: execSpy });
    const whereStub = sinon.stub().withArgs(fakeId).returns({ distinct: distinctStub });
    const findStub = sinon.stub().withArgs(fakeQuery).returns({ where: whereStub });

    applicationVersionStub = {
      find: findStub,
    };

    const { getEnvironment } = proxyquire('../../../src/db/environment-reader', { './application-version-model': applicationVersionStub });
    const target = getEnvironment;

    target(fakeQuery, fakeProjection, fakeId);

    assert.true(execSpy.calledWithExactly());
    assert.true(execSpy.calledOnce);

  });

});
