DAVFoundation / dav-js

Enable integration of JavaScript, TypeScript, and Node.js code with the DAV Network
https://developers.dav.network/
MIT License
76 stars 51 forks source link

Create tests for `src/drone-delivery/MessageParams.ts` using jest. #99

Closed mariolo1985 closed 5 years ago

mariolo1985 commented 5 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 from DAV Foundation 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.

dav-js

This repo contains the DAV JavaScript SDK. This SDK allows developers to build applications and servers that connect to the DAV network. For example, allowing a drone to find charging stations, or an autonomous car to ask for traffic data.

How you can help

In order to foster a community that is welcoming for open source contributions, it is important for us to have good test coverage. And good tests are simple, readable tests.

Here is a good opportunity to simplify one of our tests.

The Issue

We currently do not have unit testing set up for src/drone-delivery/MessageParams.ts. Please create Jest tests for the serialize() and deserialize() methods.

A good reference point would be src/ride-hailing/MissionParams.test.ts and customize it to the expected parameters and properties. If you are unsure what is expected, run npm run jest in the terminal and it should give you a hint. Also, you can reach out to our gitter channel with any questions 😄

The test you write will be similar to this:

import MessageParams from './MessageParams';

describe('MessageParams class', () => {
  let messageParams: MessageParams;
  let serializedMessageParams: any;

  beforeEach(() => {
    messageParams = new MessageParams({
      senderId: undefined
    });

    serializedMessageParams = {
      protocol: 'drone_delivery',
      senderId: undefined,
      type: 'message',
      ttl: undefined
    };
  });

  describe('serialize method', () => {
    it('should return serialized MessageParams object with the current values', () => {
      expect(messageParams.serialize()).toEqual(serializedMessageParams);
    });
  });

  describe('deserialize method', () => {
    it('should return a MessageParams instance', () => {
      const messageParamsObject = new MessageParams();
      messageParamsObject.deserialize(serializedMessageParams);
      expect(messageParamsObject).toBeInstanceOf(MessageParams);
    });

    it('should return deserialize MessageParams instance with the current parameters', () => {
      const messageParamsObject = new MessageParams();
      messageParamsObject.deserialize(serializedMessageParams);
      expect(messageParamsObject).toEqual(messageParams);
    });
  });
});

After making your changes, run npm run tslint and npm run jest to make sure our tests are passing.

Contributing to dav-js

Asking for help

We appreciate your effort in taking the time to work on this issue and help out the open source community and the foundation. If you need any help, feel free to ask below or in our gitter channel. We are always happy to help 😄

sionelt commented 5 years ago

@mariolo1985 I'll tackle this one too, if that's ok.

mariolo1985 commented 5 years ago

For sure! Go for it @sionelt.

mariolo1985 commented 5 years ago

Thanks for another quick turn around @sionelt I have merged your changes. May I suggest using lint plugins for your IDE to assist code standards on future projects?

sionelt commented 5 years ago

I am glad to help. I wish I can do more. Oh was the linting failed on the files I worked on? I do have the Eslint plugin on vs code...

mariolo1985 commented 5 years ago

@sionelt I use vs code, too 😃 Yeah I usually have the eslint plugin running and that's good for most projects. I am seeing more projects move towards typescript so it may be another plugin I have to keep running as well 😆 If plugins were better managed in vs code I wouldn't be so concerned.

sionelt commented 5 years ago

Yes, I just notice it. It was failing for the Tslint and I didn't have Tslint plugin installed. This is a great tip, I've been learning typescript. I'll make sure to run the Tslint script and passed on future PRs. thanks for the help. This makes more excited to contribute more to open source.