DAVFoundation / missioncontrol

🛰 Controls and orchestrates missions between vehicles and DAV users
MIT License
181 stars 156 forks source link

Add tests to check randomMissionsCompleted() returns an object with keys missionsCompleted and missionsCompleted7Days #28

Closed cg-cnu closed 6 years ago

cg-cnu commented 7 years ago

first-timers-only

This issue is tagged :octocat: first-timers-only. It is only for people who have never contributed to open source before, and are looking for an easy way take their first steps.

Consider this your chance to dip your toe into the world of open-source, and get some bragging rights for writing code that makes drones fly, lets cars find charging stations, helps people and goods get from place to place, and more.

Find more first-timers-only issues here:

Thank you for your help :heart:

What is this project?

DAV (Decentralized Autonomous Vehicles) is a new foundation working to build an open-source infrastructure for autonomous vehicles (cars, drones, trucks, robots, and all the service providers around them) to communicate and transact with each other over blockchain.

As an organization that believes in building a large community of open-source contributors, we often create issues like this one to help people take their first few steps into the world of open source.

Mission Control

The DAV project you are looking at is Mission Control. It is the brain in charge of orchestrating missions between DAV users and autonomous vehicles.

How you can help

Background

To help developers building on top of DAV technologies, Mission Control can start in a simulation environment. In a simulation environment, there are always a few simulated drones flying around the user, ready to take on missions. This makes it easy for developers to start building and testing without investing in hardware.

The Issue

As a project that relies on a large community of contributors, it is very important for us to have good tests to make sure changes don't break anything.

One of the functions that need testing is randomMissionsCompleted() inside /server/simulation/random.js that creates random number of missionsCompleted and missionsCompleted7Days.

The task for this issue is to test the functions return value to have the following keys

Edit test/specs/simulation.random.spec.js, adding a describe block for randomMissionsCompleted() if it does not exists and within it two tests that verify the conditions mentioned above.

To run your tests, run npm test from the project's root directory. All tests should pass.

tests

Contributing to Mission Control

TalAter commented 7 years ago

This issue is still available for first-time contributors

ghost commented 7 years ago

Hi, is this issue still available? I want to give this a try.

TalAter commented 7 years ago

It is available. Go for it! 👍

And please join our contributors gitter channel where we discuss this and other ways to get into open source

ghost commented 7 years ago

Won't adding the following test to the describe block do the work? There is already a describe block for randomMissionsCompleted in the test script.

test('returns a object with two keys', () => {
    const mock = randomMissionsCompleted();
    expect(mock).toHaveProperty('missionsCompleted', expect.any(Number));
    expect(mock).toHaveProperty('missionsCompleted7Days', expect.any(Number));
});

Isn't it not done already in the following link mentioned above:

https://github.com/malltshik/missioncontrol/commit/4df96efe88d4a1e55ca98566b9562f5ce81efe6e

Should I just modify and add the code to the script ? I'am relatively new to JavaScript, so just making sure if I understood correctly.

TalAter commented 7 years ago

It is usually better to separate it to as many granular atomic tests as possible. This way if something breaks, you know exactly what broke. And if the API changes you only have to change the tests that describe the exact thing that you change.

In this case it would mean having separate tests for missionsCompleted and missionsCompleted7Days.

There already is a test for missionsCompleted in https://github.com/DAVFoundation/missioncontrol/blob/master/test/specs/simulation.random.spec.js#L43 . You can add a similar one for missionsCompleted7Days just below it.

TalAter commented 7 years ago

@debeshadhikari how is it going with this one? Do you need any help?

ghost commented 6 years ago

Hi, I am extremely sorry for the very late response. I have been really busy and been travelling around for work. I have completed the task, and will send a pull request as soon as I settle back, which is in a couple of days. Again, I am really sorry for the delay.