Skip to content

Commit

Permalink
fixup! more tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Nov 25, 2019
1 parent 24ff52c commit e27afa7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ http://[::1]:3000/explorer/.

## Models

This app has five models:
This app has the following models:

1. `User` - representing the users of the system.
2. `Product` - a model which is mapped to a remote service by
2. `UserCredentials` - representing sensitive credentials like a password.
3. `Product` - a model which is mapped to a remote service by
`services/recommender.service`.
3. `ShoppingCartItem` - a model for representing purchases.
4. `ShoppingCart` - a model to represent a user's shopping cart, can contain
4. `ShoppingCartItem` - a model for representing purchases.
5. `ShoppingCart` - a model to represent a user's shopping cart, can contain
many items (`items`) of the type `ShoppingCartItem`.
5. `Order` - a model to represent an order by user, can have many products
6. `Order` - a model to represent an order by user, can have many products
(`products`) of the type `ShoppingCartItem`.

`ShoppingCart` and `Order` are marked as belonging to the `User` model by the
Expand All @@ -50,6 +51,10 @@ marked as having many `Order`s using the `@hasMany` model decorator. Although
possible, a `hasMany` relation for `User` to `ShoppingCart` has not be created
in this particular app to limit the scope of the example.

`User` is also marked as having one `UserCredentials` model using the `@hasOne`
decorator. The `belongsTo` relation for `UserCredentials` to `User` has not been
created to keep the scope smaller.

## Controllers

Controllers expose API endpoints for interacting with the models and more.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ describe('UserController', () => {
expect(res.body).to.not.have.property('password');
});

it('creates a new user with the given id', async () => {
// This test verifies the scenario described in our docs, see
// https://loopback.io/doc/en/lb4/Authentication-Tutorial.html
const res = await client.post('/users').send({
id: '5dd6acee242760334f6aef65',
...userData,
password: userPassword,
});
expect(res.body).to.deepEqual({
id: '5dd6acee242760334f6aef65',
...userData,
});
});

it('throws error for POST /users with a missing email', async () => {
const res = await client
.post('/users')
Expand Down

0 comments on commit e27afa7

Please sign in to comment.