Example #1
0
  t.pass('test-jobboard.js - file loaded')
});

test('Jobboard - getOrdersSince', function(t){
  return mi5Rest.getOrdersSince()
    .then(function(result){
      console.log(result);
    });
});

test('Jobboard - getOrdersUpdateSince', function(t){
  return mi5Rest.getOrdersUpdatedSince(300)
    .then(function(result){
      console.log(result);
    });
});

// Experimental - makes orders appear multiple times
test.skip('Jobboard Hack', function(t){
  return mi5Rest.reloadJobboardHack()
    .then(function(result){
      console.log(result);
    })
});

test.skip('Reload Special Order', function(t){
  return mi5Rest.reloadOrderInJobboard(3)
    .then(function(result){
      console.log(result);
    })
});
Agent.ready.then(()=>{

  //Agent.register();

  test('find Handling Robot', (t)=>{
    return Agent.searchSkill('cfp-transport')
      .then((agents) => {
        t.assert( _.isArray(agents), 'agents must be an array');
        t.assert( !_.isEmpty(agents), 'at least one agent should be in there');
        t.assert( _.isObject(agents[0]), 'each element of the array must be an object');
        //t.assert( HandlingRobot.id == agents[0].agent, 'agent must be the HandlingRobot agent id');
    });
  });

  test.skip('check cfp-transport part 1', (t)=>{
    return Agent.searchSkill('cfp-transport')
      .then((agents) => {
        return agents[0];
      })
      .then((agent) => {
        return Agent.CAcfp(agent.agent, 'cfp-transport', '')
          .then((reply) => {
            t.assert(_.isNumber(reply.price), 'reply must have a price');
            t.assert((reply.price > 0 && reply.price < 1), 'price must be between 0 and 1');
            t.equal(reply.agent, agent.agent, 'agent must be part of reply');
            return reply;
          });
      });
  });

  const mockEdge = {
    from: {
      agent: '',
      position: 40
    },
    to: {
      agent: '',
      position: 50
    }
  };
  test('check cfp-transport part 1', (t)=>{
    return Agent.searchSkill('cfp-transport')
      .then((agents) => {
        return agents[0];
      })
      .then((agent) => {
        return Agent.CAcfp(agent.agent, 'cfp-transport', '')
          .then((reply) => {
            t.assert(_.isNumber(reply.price), 'reply must have a price');
            t.assert((reply.price > 0 && reply.price < 1), 'price must be between 0 and 1');
            t.equal(reply.agent, agent.agent, 'agent must be part of reply');
            return reply;
          });
      })
      .then((reply) => {
        return Agent.CAcfpAcceptProposal(reply.agent, 'cfp-transport', mockEdge);
      })
      .then((reply) => {
        console.log('it worked :-) ', reply);
        let task = reply.informDone;
        t.deepEqual(task.task.from, mockEdge.from, 'compare from'); //TODO why doesnt the test end?
        return Promise.resolve();
      });
  });


  test('killAll', (t)=>{
    t.pass('emit SIGINT signal which kills the required HandlingRobot with a delay of 500ms');
    process.emit('SIGINT');
    setTimeout(process.exit, 500);
    t.end();
  });

});
// Test api request.
test('api request', t => async function() {
    const activity = new StreamSpotSource();
    const config = getTestConfig();
    const date = moment.utc().subtract(1, 'days').format(StreamSpotSource.dateFormat);

    // Intercept request.
    const scope = nock(StreamSpotSource.uri, {
            reqheaders: {
                'X-API-Key': config.authToken,
            },
        })
        .get(StreamSpotSource.path + config.broadcasterId + '/metric/raw')
        .query({ date })
        .replyWithFile(200, __dirname + '/response.json');

    const result = await activity.request(config);
    t.ok(result);
}());

// // Non-mocked, full-blown test. THIS HAS SIDE-EFFECTS.
// // Typically skipped unless directly testing.
test.skip('onTask', t => async function() {
    const activity = streamspot();
    const config = getTestConfig();
    const key = await activity.onTask({}, config);
    t.comment(`Uploaded ${key}`);
    t.ok(key);
}());