Example #1
0
  beforeEach(() => {
    sandbox = sinon.createSandbox();

    this.sequelize = Support.getSequelizeInstance(null, null, null, {
      replication: {
        write: Support.getConnectionOptions(),
        read: [Support.getConnectionOptions()]
      }
    });

    expect(this.sequelize.connectionManager.pool.write).to.be.ok;
    expect(this.sequelize.connectionManager.pool.read).to.be.ok;

    this.User = this.sequelize.define('User', {
      firstName: {
        type: DataTypes.STRING,
        field: 'first_name'
      }
    });

    return this.User.sync({force: true})
      .then(() => {
        readSpy = sandbox.spy(this.sequelize.connectionManager.pool.read, 'acquire');
        writeSpy = sandbox.spy(this.sequelize.connectionManager.pool.write, 'acquire');
      });
  });
    beforeEach(function(){
        sandbox = sinon.createSandbox();
        mockery.enable({
            warnOnUnregistered: false,
            warnOnReplace: false,
            useCleanCache: true
        });
        allureMock = sandbox.stub({
                getCurrentTest: function(){},
                setOptions: function() {},
                startSuite: function() {},
                endSuite: function() {},
                getSuite: function() {},
                startCase: function() {},
                endCase: function() {},
                pendingCase: function() {}
            });
        allureMock.getCurrentTest.returns("a test");
        runtimeMock = sandbox.stub({
                createStep: function() {},
                createAttachment: function() {},
                addLabel: function() {}
            });
        runtimeMock.createStep.returns(function() {});
        runtimeMock.createAttachment.returns(function() {});


        mockery.registerMock("allure-js-commons", function() {
            return allureMock;
        });
        mockery.registerMock("allure-js-commons/runtime", function() {
            return runtimeMock;
        });
        reporter = require("../../");
    });
Example #3
0
  before(() => {
    sandbox = sinon.createSandbox();

    mocks = {
      amplitude: sandbox.spy(),
      config: {
        getProperties: sinon.spy(() => ({ key: 'value'}))
      },
      log: {
        info: sandbox.spy(),
        warn: sandbox.spy(),
      },
      token: {
        verify: sandbox.spy(() => Promise.resolve({
          client_id: 'foo',
          scope: ScopeSet.fromArray(['bar:foo', 'clients:write']),
          user: '******'
        }))
      }
    };

    dependencies = {
      '../config': mocks.config,
      '../metrics/amplitude': sandbox.spy(() => mocks.amplitude),
      '../logging': () => mocks.log,
      '../token': mocks.token
    };

    route = proxyquire('../../lib/routes/verify', dependencies);
  });
Example #4
0
 beforeEach(function () {
   sandbox = sinon.createSandbox();
   mocks[SANDBOX] = sandbox;
   for (let [key, value] of _.toPairs(libs)) {
     mocks[key] = sandbox.mock(value);
   }
 });
test('### disconnect Call - OK Case ###', (t) => {
  // Data
  connector.sdkAPI = {
    logout: () => { }
  }

  // Stubs and spies
  const sandbox = sinon.createSandbox()
  const cbSpy = sandbox.spy()
  const sdkAPIStub = sandbox.stub(connector.sdkAPI, 'logout').callsFake((callback) => {
    callback(null, {})
  })

  // Execution
  disconnect.call(connector, cbSpy)

  // Tests
  t.ok(cbSpy.calledOnce)
  t.ok(cbSpy.calledWith())
  t.ok(sdkAPIStub.calledOnce)
  t.equals(connector.sdkAPI, null)

  sandbox.restore()
  t.end()
})
Example #6
0
describe('moment formatting filter', function () {
  const sandbox = sinon.createSandbox();

  beforeEach(function () {
    sandbox.useFakeTimers(moment(anchor).valueOf());

    init();
  });

  afterEach(function () {
    sandbox.restore();
  });

  it('should have a moment filter', function () {
    expect(filter).to.not.be(null);
  });

  // MMMM Do YYYY, HH:mm:ss.SSS
  it('should format moments', function () {
    expect(filter(moment())).to.be('January 1st 2014, 06:06:06.666');
  });

  it('should format dates', function () {
    expect(filter(new Date())).to.be('January 1st 2014, 06:06:06.666');
  });

  it('should return the original value if passed anything other than a moment or Date', function () {
    expect(filter('beer')).to.be('beer');
    expect(filter(1)).to.be(1);
    expect(filter([])).to.eql([]);
  });
});
  before(() => {
    sandbox = sinon.createSandbox();
    sandbox.usingPromise(BbPromise.Promise);

    baseModule = require('./prepareLocalInvoke');
    Object.freeze(baseModule);
  });
Example #8
0
describe('dev/build/lib/exec', () => {
  const sandbox = sinon.createSandbox();
  afterEach(() => sandbox.reset());

  const onLogLine = sandbox.stub();
  const log = new ToolingLog({
    level: 'verbose',
    writeTo: {
      write: chunk => {
        onLogLine(stripAnsi(chunk));
      }
    }
  });

  it('executes a command, logs the command, and logs the output', async () => {
    await exec(log, process.execPath, ['-e', 'console.log("hi")']);

    // logs the command before execution
    sinon.assert.calledWithExactly(onLogLine, sinon.match(`$ ${process.execPath}`));

    // log output of the process
    sinon.assert.calledWithExactly(onLogLine, sinon.match(/debg\s+hi/));
  });

  it('logs using level: option', async () => {
    await exec(log, process.execPath, ['-e', 'console.log("hi")'], {
      level: 'info'
    });

    // log output of the process
    sinon.assert.calledWithExactly(onLogLine, sinon.match(/info\s+hi/));
  });
});
describe('ZAFClient', () => {
  const sandbox = sinon.createSandbox()

  afterEach(() => {
    sandbox.restore()
  })

  describe('.init', () => {
    describe('given origin and app_guid exist', () => {
      describe('when a callback is passed', () => {
        const callback = function () { return 'abcxyz' }
        callback.bind = function () { return callback }

        beforeEach(() => {
          sandbox.spy(Client.prototype, 'on')
          ZAFClient.init(callback, { hash: 'origin=https://subdomain.zendesk.com&app_guid=A2' })
        })

        it('binds the callback to app.registered', () => {
          const callbackMatcher = sinon.match((cb) => {
            // performs an identity check, meaning that bind must be stubbed to return the same method
            return cb === callback
          }, 'wrong callback')
          expect(Client.prototype.on).to.have.been.calledWith('app.registered', callbackMatcher)
        })
      })
    })

    describe('given origin and app_guid are missing', () => {
      it("won't create a Client instance", () => {
        expect(ZAFClient.init()).to.equal(false)
      })
    })
  })
})
  before(() => {
    sandbox = sinon.createSandbox();
    sandbox.usingPromise(BbPromise.Promise);

    baseModule = require('../lib/prepareStepOfflineInvoke');
    Object.freeze(baseModule);
  });
Example #11
0
beforeEach(() => {
  global.sinon = sinon.createSandbox()

  // set logger to log INFO, but do not append to console
  // so that we can assert logs by logger.on('info', ...)
  logger.setup('INFO', false, [])
})
Example #12
0
describe('findObjectByTitle', () => {
  const sandbox = sinon.createSandbox();
  const savedObjectsClient = {};

  beforeEach(() => {
    savedObjectsClient.find = sandbox.stub();
  });

  afterEach(() => sandbox.restore());

  it('returns undefined if title is not provided', async () => {
    const match = await findObjectByTitle(savedObjectsClient, 'index-pattern');
    expect(match).to.be(undefined);
  });

  it('matches any case', async () => {
    const indexPattern = new SimpleSavedObject(savedObjectsClient, { attributes: { title: 'foo' } });
    savedObjectsClient.find.returns(Promise.resolve({
      savedObjects: [indexPattern]
    }));

    const match = await findObjectByTitle(savedObjectsClient, 'index-pattern', 'FOO');
    expect(match).to.eql(indexPattern);
  });
});
  describe('server stop', () => {
    const sandbox = sinon.createSandbox();

    beforeEach(() => {
      sandbox.stub(ClusterNS, 'Cluster').callsFake(function () {
        this.stub = true;
        this.close = sinon.stub();
      });
    });

    after(() => {
      sandbox.restore();
    });

    it('closes all clusters', async () => {
      const server = new Hapi.Server();
      const clusters = createClusters(server);
      const cluster = clusters.create('name', { config: true });
      expect(cluster).to.have.property('stub', true);
      sinon.assert.notCalled(cluster.close);
      await server.start();
      sinon.assert.notCalled(cluster.close);
      await server.stop();
      sinon.assert.calledOnce(cluster.close);
    });
  });
Example #14
0
  describe('list', () => {
    const sandbox = sinon.createSandbox();

    beforeEach(() => {
      sandbox.stub(Logger.prototype, 'log');
      sandbox.stub(Logger.prototype, 'error');
    });

    afterEach(() => {
      sandbox.restore();
    });

    it('outputs keys', () => {
      const keystore = new Keystore('/data/test.keystore');
      list(keystore);

      sinon.assert.calledOnce(Logger.prototype.log);
      sinon.assert.calledWith(Logger.prototype.log, 'a1.b2.c3\na2');
    });

    it('handles a nonexistent keystore', () => {
      const keystore = new Keystore('/data/nonexistent.keystore');
      list(keystore);

      sinon.assert.calledOnce(Logger.prototype.error);
      sinon.assert.calledWith(Logger.prototype.error, 'ERROR: Kibana keystore not found. Use \'create\' command to create one.');
    });
  });
Example #15
0
	beforeEach(function() {
		resource = {};
		siren = undefined;
		sandbox = sinon.createSandbox();
		sandbox.stub(console, 'error');
		sandbox.stub(console, 'warn');
	});
Example #16
0
        beforeEach(() => {
            spyContext = sinon.createSandbox();
            mkdirpStub = spyContext.stub().callsArg(1);

            date1 = new Date();
            date2 = new Date();
            date2.setDate(date1.getDate() + 1);

            fsStub = new FakeFs();
            fsStub.file("import1.less", { mtime: date1 });
            fsStub.file("import2.less", { mtime: date2 });

            mainFile = new File({ path: "main.less" });

            ImportBuffer = getImportBuffer({
                fs: fsStub,
                os: { tmpdir: () => tempDir },
                mkdirp: mkdirpStub
            });

            fakeImportLister = new FakeImportLister(fsStub, [
                "import1.less",
                "import2.less"
            ]);
            buffer = new ImportBuffer(
                fakeImportLister.listImports.bind(fakeImportLister),
                bufferKey
            );
        });
 beforeEach(() => {
   sandbox = sinon.createSandbox()
   global.window = {
     sessionStorage: {
       removeItem: sinon.stub()
     }
   }
 })
 beforeEach(function () {
   linter = new SassLinter()
   logOutput = []
   sandbox = sinon.createSandbox()
   sandbox.stub(console, 'log').callsFake(function (text) {
     logOutput.push(text)
   })
 })
Example #19
0
File: wait.js Project: heroku/cli
 beforeEach(() => {
   sandbox = sinon.createSandbox()
   cli.mockConsole()
   cli.exit.mock()
   nock.cleanAll()
   clock = lolex.install()
   clock.setTimeout = function (fn, timeout) { fn() }
 })
 beforeEach(() => {
   sandbox = sinon.createSandbox();
   mockServer = {
     log: sandbox.stub()
   };
   pipeStub = sandbox.stub();
   onStub = sandbox.stub();
 });
Example #21
0
 beforeEach(function() {
   sandbox = sinon.createSandbox()
   // Make this work when there is no `shieldsSecret` defined.
   serverSecrets.shieldsSecret = undefined
   sandbox
     .stub(serverSecrets, 'shieldsSecret')
     .value(validCredentials.password)
 })
Example #22
0
  setup(() => {
    listSize = chance.natural(INTEGER_RANGE);

    sandbox = sinon.createSandbox();

    sandbox.stub(baseGenerators, 'integer');
    baseGenerators.integer.withArgs({min: 1, max: 20}).returns(listSize);
  });
Example #23
0
    beforeEach(function () {

      sandbox = sinon.createSandbox();

      prerender.prerenderToken = 'MY_TOKEN';
      res = { writeHead: sandbox.stub(), end: sandbox.stub() };
      next = sandbox.stub();
    });
Example #24
0
	beforeEach(() => {
		sandbox = sinon.createSandbox();
		responseStub = {
			code: sandbox.stub()
		};
		hStub = {
			response: sandbox.stub().returns(responseStub)
		};
	});
Example #25
0
describe('server.registerFieldFormat(createFormat)', () => {
  const sandbox = sinon.createSandbox();

  let server;
  beforeEach(async () => {
    const kbnServer = createServer();
    await kbnServer.ready();
    server = kbnServer.server;
  });

  afterEach(() => {
    sandbox.restore();
  });

  it('throws if createFormat is not a function', () => {
    expect(() => server.registerFieldFormat()).to.throwError(error => {
      expect(error.message).to.match(/createFormat is not a function/i);
    });
  });

  it('calls the createFormat() function with the FieldFormat class', () => {
    const createFormat = sinon.stub();
    server.registerFieldFormat(createFormat);
    sinon.assert.calledOnce(createFormat);
    sinon.assert.calledWithExactly(createFormat, sinon.match.same(FieldFormat));
  });

  it('passes the returned class to the FieldFormatsService', async () => {
    const { FieldFormatsService: ActualFFS } = FieldFormatsServiceNS;
    sandbox.stub(FieldFormatsServiceNS, 'FieldFormatsService').callsFake((...args) => {
      return new ActualFFS(...args);
    });

    const { FieldFormatsService } = FieldFormatsServiceNS;
    class FooFormat {
      static id = 'foo'
    }
    server.registerFieldFormat(() => FooFormat);

    const fieldFormats = await server.fieldFormatServiceFactory({
      getAll: () => ({}),
      getDefaults: () => ({})
    });

    sinon.assert.calledOnce(FieldFormatsService);
    sinon.assert.calledWithExactly(
      FieldFormatsService,
      // array of fieldFormat classes
      [sinon.match.same(FooFormat)],
      // getConfig() function
      sinon.match.func
    );

    const format = fieldFormats.getInstance({ id: 'foo' });
    expect(format).to.be.a(FooFormat);
  });
});
Example #26
0
  setup(() => {
    const fetchMiddleware = any.simpleObject();

    sandbox = sinon.createSandbox();

    sandbox.stub(devTools, 'composeWithDevTools');
    sandbox.stub(fetchMiddlewareFactory, 'default').withArgs(session).returns(fetchMiddleware);
    sandbox.stub(redux, 'applyMiddleware').withArgs(fetchMiddleware).returns(appliedFetch);
  });
Example #27
0
 beforeEach(() => {
   sandbox = sinon.createSandbox();
   sandbox.stub(carsConfig, 'get');
   mockLogger = {
     log: sandbox.stub()
   };
   nock.disableNetConnect();
   moxios.install();
 });
Example #28
0
  setup(() => {
    sandbox = sinon.createSandbox();
    sandbox.stub(dependencies, 'default');
    sandbox.stub(storeCreator, 'configureStore').withArgs({initialState}).returns(store);
    sandbox.stub(historyListener, 'default');
    sandbox.stub(renderer, 'default');
    sandbox.stub(ga, 'initialize');

    window.__INITIAL_STATE__ = initialState;
  });
Example #29
0
test('hostArch cannot determine ARM version', t => {
  const sandbox = sinon.createSandbox()

  sandbox.stub(process, 'arch').value('arm')
  sandbox.stub(process, 'config').value({variables: {arm_version: '99'}})

  t.is(targets.hostArch(), 'arm')

  sandbox.restore()
})
Example #30
0
test('validateListFromOptions works for armv7l host and target arch', t => {
  const sandbox = sinon.createSandbox()

  sandbox.stub(process, 'arch').value('arm')
  sandbox.stub(process, 'config').value({variables: {arm_version: '7'}})

  t.deepEqual(targets.validateListFromOptions({}, 'arch'), ['armv7l'])

  sandbox.restore()
})