Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic unit tests hooked into Travis CI #118

Open
2 tasks
yochannah opened this issue Feb 15, 2019 · 8 comments · May be fixed by #147
Open
2 tasks

Add basic unit tests hooked into Travis CI #118

yochannah opened this issue Feb 15, 2019 · 8 comments · May be fixed by #147

Comments

@yochannah
Copy link
Member

It would be nice to have some basic tests hooked into Travis to test the following things:

  • the package builds correctly
  • the API methods do what they're supposed to do correctly (full docs/listing available on the registry swagger docs site

The reason I say this is I managed to merge a PR without testing one method, and then had to revert it when I realised that one method had broken :(

@harshil1712
Copy link

Hey @yochannah I would like to take this. I have very little experience with writing tests, but this seems the right opportunity to get started.

@yochannah
Copy link
Member Author

@harshil1712 that sounds amazing! Do you know where you'd plan to start or would you like to chat first?

@harshil1712
Copy link

It would be great if I could get some help. I have a few questions.

  • Is there any preferred testing library that we should use?
  • Can you please give examples of the use cases that require the test?

As I mentioned I am new with testing, and there might be a lot of questions coming from my end. 😅

@yochannah
Copy link
Member Author

@harshil1712 okay, here's a mega response - I'd suggest working through these in order. Just the basic use case alone would be amazing.

testing library: how about jest? this will align with some other intermine-based tools.

use-cases:

basic

This won't require a testing library, probably just a travis yml file, possibly with a shell script as well. if the script completes = success, if it errors out partway = failure.

  • does the setup scripting work correctly? (e.g. following the readme docs, set up a mongo, run the initregistry script and the createuser script).

advanced - unit tests

check directly against the mongo DB that:

  • POST to /instances - does the POST get added to the DB correctly?
  • POST to /instances - if a namespace already exists, does the api return an error? namespaces should be unique.
  • GET to /instances - should return the correct number of results WHEN
    • there are no params (should return all intermine instances)
    • param: q=flymine
    • param: mines=dev should not return any intermines with "isProduction": true
    • param: mines=prod should not return any intermines with "isProduction": false
    • param: mines=all should return a count of intermines that is sum of the total of dev and prod intermines.
  • PUT to /instances should update the given instance, and only the given instance.
  • PUT to /instances shouldn't allow a namespace to be changed
  • DELETE to /instances should delete the given instance and only the given instance

Even more advanced - UI-based tests

ideally using cypress.

[TODO, ADD DETAILS AT SOME POINT] :)

@harshil1712
Copy link

Hey @yochannah,
I've added the travis.yml file in my forked repo. But I am not sure how do I add checks for the setup scripts? To check that, won't we need a testing library?

basic

This won't require a testing library, probably just a travis yml file, possibly with a shell script as well. if the script completes = success, if it errors out partway = failure.

does the setup scripting work correctly? (e.g. following the readme docs, set up a mongo, run the initregistry script and the createuser script).

@yochannah
Copy link
Member Author

@harshil1712 if you know a way to do this with a testing library, go ahead!

I was thinking something along the lines of a shell script - an example is here: https://github.com/intermine/bluegenes/blob/dev/.travis.yml#L30

@harshil1712
Copy link

@yochannah thank you for the link. It helped me understand the approach better.
My .travis.yml file contains the following line of code

language: node_js
node_js:
 - "node"
services: mongodb

script:
  # Install packages
  - npm install
  - export MONGODB_URL=mongodb://localhost:27017/registry
  # Running createUser.js
  - node createUser.js
  # Populating the instance
  - node initRegistry.js
  # Start server
  - npm start

This seems to work until the node createUser.js is ran, since it asks for a username and a password, and since we cannot provide an input, the next step is not executed .
And we are using this username and password in the initRegister.js file as well. Hence updating this file is also not possible with this approach, as per my understanding.
I am not sure if there's a way to do this apart from writing tests.
Please guide me for my next step.

@dmahajan980
Copy link
Contributor

@yochannah I would like to work on this issue if it's still available. I haven't written any tests prior to this, so it will help me to learn more about writing tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants