The next step is to do the same thing with the user-ms microservice. Since we are using Google Endpoints, the only reason to have this microservice is if you treat the user as a customer, for example, and maybe you could use the basic authentication with the user password and login as part of the authentication/authorization process.
As you might have guessed, the project structure is almost the same as for order-ms. The user-ms code will have the following structure:
Before we enter the code for user-ms, copy and paste the following files from the order-ms service into the user-ms service:
- tslint.json
- tsconfig.json
- stryker.conf.js
- Dockerfile
- .prettierrc
- .gitignore
- .dockerignore
- test/routes/api.spec/ts
- test.mocha.opts
- src/server.ts
- src/utility/errorHandler.ts
- src/utility/logger.ts
- src/routes/api.ts
- src/models/applicationType.ts
Run the tests, as follows:
$ npm run test
should respond with HTTP 200 status (98ms)
should respond with success message
userRoute
[2018-12-30T03:34:43.807Z] [info] => [GET] [/users] NO_USER
[2018-12-30T03:34:43.829Z] [info] => [GET] [/users/:{username}] user with username NO_USER not found
should respond with HTTP 404 status because there is no user
[2018-12-30T03:34:43.905Z] [info] => [POST] [/users] { _id: null,
username: 'John',
firstName: 'John',
lastName: 'Doe',
email: 'John@memail.com',
password: 'password',
phone: '5555555',
userStatus: 1 }
[2018-12-30T03:34:44.021Z] [info] => John
should create a new user and retrieve it back (189ms)
[2018-12-30T03:34:44.022Z] [info] => [GET] [/users] John
should return the user created on the step before
[2018-12-30T03:34:44.030Z] [info] => [PATCH] [/users] John
should updated the user John
[2018-12-30T03:34:44.046Z] [info] => [GET] [/users] John_Updated
should return the user updated on the step before
[2018-12-30T03:34:44.055Z] [info] => [PATCH] [/users] Mary
[2018-12-30T03:34:44.058Z] [info] => [PATCH] [/users/:{username}] user with username Mary not found
should return 404 because the user does not exist
[2018-12-30T03:34:44.060Z] [warn] => [DELETE] [/users] John_Updated
should remove an existent user
[2018-12-30T03:34:44.068Z] [warn] => [DELETE] [/users] Mary
[2018-12-30T03:34:44.070Z] [info] => [DELETE] [/users/:{username}] user with username Mary not found
should return 404 when it is trying to remove an user because the user does not exist
10 passing (401ms)
Following, is the command to run test:
$ npm run test:mutation
The result is shown in the following screenshot:
After that, redo the same steps as you did for order-ms and, in the end, you will have a Travis CI pipeline deploy the application for you, and also a user-ms Developer Portal:
The following screenshot shows the POST/users definitions:
![](assets/f512abb9-a2af-40c9-9580-00451e1bd82e.png)
The following screenshot shows the new version of user-ms to production:
![](assets/8fb48c96-8e71-43bf-aec1-2d454ede185a.png)