Example #1
0
  it("should add tag and return 201 latest package json", function () {
    /*jslint nomen: true*/
    var pkgMeta = {
      name     : "test",
      "_rev"   : 1,
      versions : {
        "0.1.0" : {}
      },
      "dist-tags" : {
        latest : "0.1.0"
      }
    };
    registry.getPackage.returns(pkgMeta);

    this.tagFn({
      headers     : { "content-type" : "application/json" },
      params      : {
        name    : pkgMeta.name,
        tagname : "release"
      },
      body        : '"0.1.0"',
      originalUrl : "/test/0.0.1-dev/tag/release"
    }, this.res);

    pkgMeta._rev = 2;
    pkgMeta["dist-tags"].release = "0.1.0";

    sinon.assert.called(registry.setPackage);
    sinon.assert.calledWith(registry.setPackage, pkgMeta);
    sinon.assert.calledOnce(this.res.status);
    sinon.assert.calledWith(this.res.status, 201);
    sinon.assert.called(this.json);
    sinon.assert.calledWith(this.json, pkgMeta);
  });
Example #2
0
  it("should reset revision if it's a checksum", function () {
    /*jslint nomen: true*/
    var pkgMeta = {
      name        : "test",
      "_rev"      : "011f2254e3def8ab3023052072195e1a",
      "_proxied"  : false,
      "dist-tags" : { latest : "0.0.1-dev" },
      versions    : { "0.0.1-dev" : {} }
    };
    registry.getPackage.returns(pkgMeta);

    this.publishFn({
      settingsStore : this.settingsStore,
      headers       : { "content-type" : "application/json" },
      params        : {
        name    : "test",
        version : "0.0.1-dev"
      },
      originalUrl : "/test/0.0.1-dev"
    }, this.res);

    pkgMeta._rev = 1;

    sinon.assert.called(attachment.refreshMeta);
    sinon.assert.calledWith(attachment.refreshMeta, this.settingsStore,
      pkgMeta);
    sinon.assert.called(registry.setPackage);
    sinon.assert.calledWith(registry.setPackage, pkgMeta);
    sinon.assert.calledOnce(this.res.status);
    sinon.assert.calledWith(this.res.status, 200);
    sinon.assert.called(this.json);
    sinon.assert.calledWith(this.json, "0.0.1-dev");
  });
Example #3
0
 webhook.create(req, function(err, hook) {
     sinon.assert.called(userStub);
     sinon.assert.called(githubStub);
     userStub.restore();
     githubStub.restore();
     done();
 });
Example #4
0
  it("should create new package and bounce revision", function () {
    /*jslint nomen: true*/
    var pkgMeta = {
      name       : "test",
      "_rev"     : 1,
      "_proxied" : false,
      versions   : {
        "0.0.1-dev" : {}
      }
    };
    registry.getPackage.returns(pkgMeta);

    this.publishFn({
      settingsStore : this.settingsStore,
      headers       : { "content-type" : "application/json" },
      params        : {
        name    : "test",
        version : "0.0.1-dev"
      },
      originalUrl : "/test/0.0.1-dev"
    }, this.res);

    pkgMeta._rev++;

    sinon.assert.called(attachment.refreshMeta);
    sinon.assert.calledWith(attachment.refreshMeta, this.settingsStore,
      pkgMeta);
    sinon.assert.called(registry.setPackage);
    sinon.assert.calledWith(registry.setPackage, pkgMeta);
    sinon.assert.calledOnce(this.res.status);
    sinon.assert.calledWith(this.res.status, 200);
    sinon.assert.called(this.json);
    sinon.assert.calledWith(this.json, "0.0.1-dev");
  });
Example #5
0
  it("should add package and persist registry for new scoped package", function () {
    registry.getPackage.returns(null);

    this.publishFullFn({
      settingsStore : this.settingsStore,
      headers       : { "content-type" : "application/json" },
      params        : { name : "@scoped/test" },
      originalUrl   : "/@scoped%2ftest",
      body          : {
        "_id"  : "@scoped/test",
        "name" : "@scoped/test"
      }
    }, this.res);

    var pkgMeta = {
      "_id"      : "@scoped/test",
      "name"     : "@scoped/test",
      "_rev"     : 1,
      "_proxied" : false
    };
    sinon.assert.called(attachment.refreshMeta);
    sinon.assert.calledWith(attachment.refreshMeta, this.settingsStore,
      pkgMeta);
    sinon.assert.called(registry.setPackage);
    sinon.assert.calledWith(registry.setPackage, pkgMeta);
    sinon.assert.calledOnce(this.res.status);
    sinon.assert.calledWith(this.res.status, 200);
    sinon.assert.called(this.json);
    sinon.assert.calledWith(this.json, {"ok" : true});
  });
Example #6
0
  it("should add tag and return latest version number in body", function () {
    registry.getPackage.returns(null);

    this.publishFn({
      settingsStore : this.settingsStore,
      headers       : { "content-type" : "application/json" },
      params        : {
        name    : "test",
        version : "0.0.1-dev",
        tagname : "latest"
      },
      originalUrl : "/test/0.0.1-dev/-tag/latest"
    }, this.res);

    var pkgMeta = {
      name        : "test",
      "_rev"      : 1,
      description : undefined,
      readme      : undefined,
      versions    : {"0.0.1-dev" : {}},
      "dist-tags" : {latest : "0.0.1-dev"},
      "_proxied"  : false
    };

    sinon.assert.called(attachment.refreshMeta);
    sinon.assert.calledWith(attachment.refreshMeta, this.settingsStore,
      pkgMeta);
    sinon.assert.called(registry.setPackage);
    sinon.assert.calledWith(registry.setPackage, pkgMeta);
    sinon.assert.calledOnce(this.res.status);
    sinon.assert.calledWith(this.res.status, 200);
    sinon.assert.called(this.json);
    sinon.assert.calledWith(this.json, "0.0.1-dev");
  });
Example #7
0
 it('calls the functions in _afterSetupFns one by one', function () {
   const spy = sinon.spy();
   const anotherSpy = sinon.spy();
   instance._afterSetup(spy);
   instance._afterSetup(anotherSpy);
   instance.setup();
   sinon.assert.called(spy);
   sinon.assert.called(anotherSpy);
 });
Example #8
0
        .then(() => {
          sinon.assert.called(plugins[0].jobStart);
          sinon.assert.called(plugins[1].jobStart);
          sinon.assert.called(plugins[2].jobStart);

          sinon.assert.notCalled(plugins[0].jobEnd);
          sinon.assert.notCalled(plugins[1].jobEnd);
          sinon.assert.notCalled(plugins[2].jobEnd);
        });
Example #9
0
        milestone.get('user', 'repo', 1, 2, 'token', function(err, milestone) {
            assert.equal(err, 'github error');
            assert.equal(githubStub.callCount, 2);
            sinon.assert.called(milestoneFindOneStub);
            sinon.assert.called(githubStub);

            milestoneFindOneStub.restore();
            githubStub.restore();

            done();
        });
Example #10
0
 milestone.get('user', 'repo', 1, 2, 'token', function(err, milestone) {
     assert.deepEqual(milestone, {
         repo: 1,
         pull: 2,
         number: 3
     });
     sinon.assert.called(milestoneStub);
     sinon.assert.called(githubStub);
     milestoneStub.restore();
     githubStub.restore();
     done();
 });
Example #11
0
  it("should update and persist if _rev is same inside document", function () {
    var pkgMeta = {
      "_id"  : "test",
      "name" : "test",
      "_rev" : 2,
      "versions" : {
        "0.0.1" : {},
        "0.0.2" : {}
      }
    };
    registry.getPackage.returns(pkgMeta);

    this.publishFullFn({
      settingsStore : this.settingsStore,
      headers       : { "content-type" : "application/json" },
      params        : { name : "test" },
      originalUrl   : "/test",
      body          : {
        "_id"  : "test",
        "name" : "test",
        "_rev" : 2,
        "versions" : {
          "0.0.1" : {},
          "0.0.2" : {},
          "0.0.3" : {}
        }
      }
    }, this.res);

    var newPkgMeta = {
      "_id"  : "test",
      "name" : "test",
      "_rev" : 3,
      "_proxied": false,
      "versions" : {
        "0.0.1" : {},
        "0.0.2" : {},
        "0.0.3" : {}
      }
    };

    sinon.assert.called(attachment.refreshMeta);
    sinon.assert.calledWith(attachment.refreshMeta, this.settingsStore,
      newPkgMeta);
    sinon.assert.called(registry.setPackage);
    sinon.assert.calledWith(registry.setPackage, newPkgMeta);
    sinon.assert.calledOnce(this.res.status);
    sinon.assert.calledWith(this.res.status, 200);
    sinon.assert.called(this.json);
    sinon.assert.calledWith(this.json, {"ok" : true});
  });
Example #12
0
  'should register event-function pair': function () {
    var listener1 = sinon.spy();
    var listener2 = sinon.spy();

    this.hub.after({
      'a' : listener1,
      'b' : listener2
    });
    this.hub.emit('a');
    this.hub.emit('b');

    sinon.assert.called(listener1);
    sinon.assert.called(listener2);
  },
Example #13
0
 it('should set the userId to the logged in user in an existing where', () => {
     sandbox.stub(WalletModel, 'observe');
     WalletScript(WalletModel);
     sinon.assert.called(WalletModel.observe);
     const ev = WalletModel.observe.args[1][0];
     ev.should.equal('access');
     const cb = WalletModel.observe.args[1][1];
     const ctx = {
         instance: { },
         options: {
             accessToken: {
                 userId: '999'
             }
         },
         query: {
             where: {
                 description: 'blah'
             }
         }
     };
     const next = sinon.stub();
     cb(ctx, next);
     ctx.query.where.should.deep.equal({
         userId: '999',
         description: 'blah'
     });
     sinon.assert.calledOnce(next);
 });
Example #14
0
      it('should mark the job as failed if saving to ES fails', async () => {
        const job = {
          _id: 'shouldSucced',
          _source: {
            timeout: 1000,
            payload: 'test'
          }
        };

        sinon.stub(mockQueue.client, 'callWithInternalUser')
          .withArgs('update')
          .returns(Promise.reject({ statusCode: 413 }));

        const workerFn = function (jobPayload) {
          return new Promise(function (resolve) {
            setTimeout(() => resolve(jobPayload), 10);
          });
        };
        const worker = new Worker(mockQueue, 'test', workerFn, defaultWorkerOptions);
        const failStub = getFailStub(worker);

        await worker._performJob(job);
        worker.destroy();

        sinon.assert.called(failStub);
      });
Example #15
0
                it('should write the value to the file system', function () {
                    var args = fs.writeFile.lastCall.args;
                    assert.equal(args[0], PATH + '/gpio7/value');
                    assert.equal(args[1], '1');

                    sinon.assert.called(onSetup);
                });
Example #16
0
                    it('should set the channel edge to ' + edge_mode, function() {
                        sinon.assert.called(fs.writeFile);

                        var args1 = fs.writeFile.getCall(1).args;
                        assert.equal(args1[0], PATH + '/gpio7/edge');
                        assert.equal(args1[1], edge_mode);
                    });
    it("Opens the localhost address as default", function () {
        var args = stub.getCall(0).args;
        sinon.assert.called(stub);

        assert.equal(args[0], instance.options.urls.local);
        assert.equal(args[1], "google chrome");
    });
Example #18
0
 .then(() => {
   sinon.assert.called(stubs.signAddon);
   sinon.assert.calledWithMatch(
     stubs.signAddon,
     {id: getManifestId(manifestWithoutApps)}
   );
 });
Example #19
0
 it('logs debug packets when verbose', () => {
   const log = new ConsoleStream({verbose: true});
   const localProcess = fakeProcess();
   // $FLOW_IGNORE: fake process for testing reasons.
   log.write(packet({level: bunyan.DEBUG}), {localProcess});
   sinon.assert.called(localProcess.stdout.write);
 });
Example #20
0
  it('renders menu items', () => {
    let clock  = sinon.useFakeTimers();
    let config = [
      {
        url: '/#/',
        label: 'menu.start'
      },
      {
        url: '/#/cmp',
        label: 'Test Component'
      }
    ];

    sinon.stub(MenuStore, 'getItems', () => config);

    const result = TestUtils.renderIntoDocument(<Menu items={[]} />);
    clock.tick(1000);
    const component = ReactDOM.findDOMNode(result);

    let items = component._childNodes;
    chai.expect(items).to.have.length(2);
    sinon.assert.called(MenuStore.getItems);

    let menuItem1 = items[0];
    let itemprop  = menuItem1._childNodes[0];
    chai.expect(itemprop._attributes.href._nodeValue).to.equal('/#/');
    chai.expect(itemprop._childNodes[0]._tagName).to.equal('span');
    chai.expect(itemprop._tagName).to.equal('a');
    chai.expect(itemprop._childNodes[0]._childNodes[0]._nodeValue).to.equal('Homepage');
    chai.expect();

    MenuStore.getItems.restore();
    clock.restore();
  });
Example #21
0
 function runAssertions() {
   const { session } = store.state.core;
   assert.equal(session.id, '123');
   assert.equal(session.username, 'e_fermi');
   assert.deepEqual(session.kind, ['cool-guy-user']);
   sinon.assert.called(assignStub);
 }
Example #22
0
    it('should initializes and observe memory store correctly', () => {
      const store = MemoryStore.create('/foo/:bar');
      store.observe({ bar: 'bar' }, onChange);
      store.set({ bar: 'bar' }, 'foo');

      sinon.assert.called(onChange);
    });
Example #23
0
        milestone.get('user', 'repo', 1, 2, 'token', function(err, milestone) {
            assert.equal(err, 'mongodb error');
            sinon.assert.called(milestoneFindOneStub);

            milestoneFindOneStub.restore();
            done();
        });
Example #24
0
     async () => {
       const {params, remoteFirefox} = prepareExtensionRunnerParams({
         fakeRemoteFirefox: {
           reloadAddon: sinon.spy(
             () => Promise.reject(Error('Reload failure'))
           ),
         },
       });

       const runnerInstance = new FirefoxDesktopExtensionRunner(params);
       await runnerInstance.run();

       await runnerInstance.reloadAllExtensions()
         .then((results) => {
           const error = results[0].reloadError;
           assert.equal(
             error instanceof WebExtError,
             true
           );
           const {sourceDir} = params.extensions[0];
           assert.ok(error && error.message.includes(
             `Error on extension loaded from ${sourceDir}: `
           ));
         });

       sinon.assert.called(remoteFirefox.reloadAddon);
     });
Example #25
0
        it('executes the function that was passed in to the constructor', function() {
            var execute = sinon.spy();
            var stage = new Stage(null, null, execute);
            stage.execute(null);

            sinon.assert.called(execute);
        });
Example #26
0
                it('should export the channel', function() {
                    sinon.assert.called(fs.writeFile);

                    var args0 = fs.writeFile.getCall(0).args;
                    assert.equal(args0[0], PATH + '/export');
                    assert.equal(args0[1], '7');
                });
    it("should render a session top bar when authenticated", () => {
      const session = {
        authenticated: true,
        server: "http://test.server/v1",
        credentials: {
          username: "******",
          password: "******",
        }
      };
      const logout = sandbox.spy();
      const node = createComponent(App, {
        session,
        logout,
        notificationList: []
      });

      const infoBar = node.querySelector(".session-info-bar");
      expect(infoBar).to.exist;

      const content = infoBar.textContent;
      expect(content).to.contain(session.server);
      expect(content).to.contain(session.credentials.username);
      expect(content).to.not.contain(session.credentials.password);

      Simulate.click(node.querySelector(".btn-logout"));

      sinon.assert.called(logout);
    });
Example #28
0
                it('should set the channel direction to out by default', function() {
                    sinon.assert.called(fs.writeFile);

                    var args2 = fs.writeFile.getCall(2).args;
                    assert.equal(args2[0], PATH + '/gpio7/direction');
                    assert.equal(args2[1], 'out');
                });
Example #29
0
 .then(({signAddon}) => {
   sinon.assert.called(signAddon);
   // This should call signAddon() with the server generated
   // ID that was saved to the source directory from the previous
   // signing result.
   sinon.assert.calledWithMatch(signAddon, {id: 'auto-generated-id'});
 });
Example #30
0
  it('enables verbose more from config file', async () => {
    const logStream = fake(new ConsoleStream());
    const fakeCommands = fake(commands, {
      lint: () => Promise.resolve(),
    });

    const customConfig = path.resolve('custom/web-ext-config.js');

    const loadJSConfigFile = makeConfigLoader({
      configObjects: {
        [customConfig]: {
          verbose: true,
        },
      },
    });

    await execProgram(
      ['lint', '--config', customConfig],
      {
        commands: fakeCommands,
        runOptions: {
          discoverConfigFiles: async () => [],
          loadJSConfigFile,
          logStream,
        },
      }
    );

    sinon.assert.called(logStream.makeVerbose);
  });