{"action":"created","issue":{"url":"https://api.github.com/repos/alanraso/teste-probot/issues/86","repository_url":"https://api.github.com/repos/alanraso/teste-probot","labels_url":"https://api.github.com/repos/alanraso/teste-probot/issues/86/labels{/name}","comments_url":"https://api.github.com/repos/alanraso/teste-probot/issues/86/comments","events_url":"https://api.github.com/repos/alanraso/teste-probot/issues/86/events","html_url":"https://github.com/alanraso/teste-probot/issues/86","id":482510072,"node_id":"MDU6SXNzdWU0ODI1MTAwNzI=","number":86,"title":"[Track 3] Login mutation","user":{"login":"taki-tiler-server[bot]","id":54289301,"node_id":"MDM6Qm90NTQyODkzMDE=","avatar_url":"https://avatars2.githubusercontent.com/in/38980?v=4","gravatar_id":"","url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D","html_url":"https://github.com/apps/taki-tiler-server","followers_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/followers","following_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/repos","events_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/received_events","type":"Bot","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2019-08-19T20:25:52Z","updated_at":"2019-08-19T20:32:34Z","closed_at":null,"author_association":"NONE","body":"In this track, you will implement a login mutation fully integrated with the database. There are many ways of implementing an [authentication](https://en.wikipedia.org/wiki/Authentication_server). The way we're doing it is: the user sends a password to prove that he is who he claims, and then the server provides a token that allows him to access some data on future requests. This token generally have an expiration, after which the user has to login again to get a new one. \n\n# Step 1 - The mutation setup\n### Estimated time: 1 hour\n\nLet's start with baby steps, by creating the mutation prototype, with no integration with the dabatase (yet).\n\nLet's call the mutation `Login`. It should receive an e-mail and a password as parameters and return the following structure on body:\n\n```json\n{\n  \"data\": {\n    \"Login\": {\n      \"user\": {\n        \"name\": \"User Name\",\n        \"email\": \"User e-mail\"\n        // More user fields\n      },\n      \"token\": \"the_token\"\n    }\n  } \n}\n```\n\n**Note:** Did you notice that there is a `data` object wrapping the `Login` response? Don't worry, it's the GraphQL response format. It wraps all the successful response data inside the `data` object and all the errors in an `errors` array of objects. You can read more about it [here](https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#data).\n\nFor now, you can return the above structure populated with some mock data.\n"},"comment":{"url":"https://api.github.com/repos/alanraso/teste-probot/issues/comments/522742199","html_url":"https://github.com/alanraso/teste-probot/issues/86#issuecomment-522742199","issue_url":"https://api.github.com/repos/alanraso/teste-probot/issues/86","id":522742199,"node_id":"MDEyOklzc3VlQ29tbWVudDUyMjc0MjE5OQ==","user":{"login":"taki-tiler-server[bot]","id":54289301,"node_id":"MDM6Qm90NTQyODkzMDE=","avatar_url":"https://avatars2.githubusercontent.com/in/38980?v=4","gravatar_id":"","url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D","html_url":"https://github.com/apps/taki-tiler-server","followers_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/followers","following_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/repos","events_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/taki-tiler-server%5Bbot%5D/received_events","type":"Bot","site_admin":false},"created_at":"2019-08-19T20:32:34Z","updated_at":"2019-08-19T20:32:34Z","author_association":"NONE","body":"# Step 4 - The test 🤓\n### Estimated time: 4 hours\n\nThis is another super-important concept on the process of building your own server. Have you ever stopped to think about how you would test if your code works? 🤔\nIf you thought about performing the query/mutation on one of those applications (browser, graphiql, graphql playground) and checking if it works as expected, that's one way of doing it. But we have a more solid proposal: writing more code for tests! The principle is simple: you give an entrance and check if the response is the expected. Why is it better? Well, some advantages:\n\n1. The time gain: you write your test once, and then you can run it whenever you want.\n1. While you develop other features, you can keep running the tests for all the previous implemented queries/mutation to make sure they are still working.\n1. Test codes can serve as a kind of documentation as well. People who read them are able to know all the particular scenarios of a query/mutation.\n\nIf you search on the Internet, you'll find out there are many ways to test a code. Depending on the project, people decide to use one, or several of them. Here, we're going to write `Integration tests`. For each query/mutation of your server, you're going to setup the database for them, provide some input scenarios, and then check if the response is given as expected.\n\nLet's talk about another libraries (we use a lot of them!) that helps us to test our code: [mocha](https://mochajs.org/), for test setup; [chai](https://www.chaijs.com/), for the assetions; and [supertest](https://github.com/visionmedia/supertest), to simulate a server running.\n\nYour task now is to install these libraries and write one test for your recently implemented Login mutation. Some important things to have on mind:\n\n1. You can either create an instance of your server with `supertest`, or just create an agent and send requests to your `localhost:3000/`. If the second option is chosen, you should run your server along with the tests.\n1. Remember how you connected your server with the database? We said at the time about having a second container for tests with docker. That's right, we're going to use a second database for the tests, so we don't interfere with our normal database on the process. Before actually running your tests, you should connect with this test dabatase, just like you did when running the server locally.\n1. Try to write a test script on `package.json`, so you can just run `npm run test` on terminal to perform them.\n1. Your test should predict as much scenarios as possible. In case of the Login mutation, some examples are:\n  1. \"Success case\": an existing e-mail with the right password is given to the system.\n  1. \"Wrong password\": the input has a valid existing e-mail, but the password is not right.\n  1. \"User not found\": e-mail sent on input is not present on database.\n  1. \"E-mail with invalid format\": e-mail sent on input has an invalid format.\n"}}
{"actor":{"display_login":"taki-tiler-server"}}