From e27afa73201ea970bd5a7ec8e3cb05911b2f294e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 25 Nov 2019 09:26:09 +0100 Subject: [PATCH] fixup! more tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- README.md | 15 ++++++++++----- .../acceptance/user.controller.acceptance.ts | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 04a65a043..c0da63109 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/packages/shopping/src/__tests__/acceptance/user.controller.acceptance.ts b/packages/shopping/src/__tests__/acceptance/user.controller.acceptance.ts index b0cff0ed9..259809959 100644 --- a/packages/shopping/src/__tests__/acceptance/user.controller.acceptance.ts +++ b/packages/shopping/src/__tests__/acceptance/user.controller.acceptance.ts @@ -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')