|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright CERN and copyright holders of ALICE O2. This software is |
| 4 | + * distributed under the terms of the GNU General Public License v3 (GPL |
| 5 | + * Version 3), copied verbatim in the file "COPYING". |
| 6 | + * |
| 7 | + * See http://alice-o2.web.cern.ch/license for full licensing information. |
| 8 | + * |
| 9 | + * In applying this license CERN does not waive the privileges and immunities |
| 10 | + * granted to it by virtue of its status as an Intergovernmental Organization |
| 11 | + * or submit itself to any jurisdiction. |
| 12 | + */ |
| 13 | + |
| 14 | +const { expect } = require('chai'); |
| 15 | +const { createOrUpdateUser } = require('../../../../../lib/server/services/user/createOrUpdateUser'); |
| 16 | + |
| 17 | +module.exports = () => { |
| 18 | + it('should successfully create the user', async () => { |
| 19 | + const externalId = 1000; |
| 20 | + const name = 'testUser'; |
| 21 | + |
| 22 | + const user = await createOrUpdateUser({ personid: externalId, name }); |
| 23 | + |
| 24 | + // User should exist now |
| 25 | + expect(user).not.to.be.null; |
| 26 | + // Id should be filled automatically |
| 27 | + expect(user.id).not.to.be.null; |
| 28 | + // ExternalId and name should be equal |
| 29 | + expect(user.externalId).to.equal(externalId); |
| 30 | + expect(user.name).to.equal(name); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should successfully update the user', async () => { |
| 34 | + const externalId = 1001; |
| 35 | + const name = 'testUser'; |
| 36 | + const updatedName = 'testUserUpdated'; |
| 37 | + |
| 38 | + // Create user |
| 39 | + const user = await createOrUpdateUser({ personid: externalId, name }); |
| 40 | + |
| 41 | + // Update user |
| 42 | + const updatedUser = await createOrUpdateUser({ personid: externalId, name: updatedName }); |
| 43 | + |
| 44 | + // Users should exist now |
| 45 | + expect(user).not.to.be.null; |
| 46 | + expect(updatedUser).not.to.be.null; |
| 47 | + // Id should be filled automatically |
| 48 | + expect(user.id).not.to.be.null; |
| 49 | + // Id of user and updatedUser should be the same because it is updated |
| 50 | + expect(user.id).to.equal(updatedUser.id); |
| 51 | + // ExternalId should be equal |
| 52 | + expect(user.externalId).to.equal(updatedUser.externalId); |
| 53 | + // Name should be updated |
| 54 | + expect(updatedUser.name).to.equal(updatedName); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should not update the user but still return the same user', async () => { |
| 58 | + const externalId = 1001; |
| 59 | + const name = 'testUser'; |
| 60 | + |
| 61 | + // Create user |
| 62 | + const user = await createOrUpdateUser({ personid: externalId, name }); |
| 63 | + |
| 64 | + // Update user with the same variables (should stay the same) |
| 65 | + const sameUser = await createOrUpdateUser({ personid: externalId, name }); |
| 66 | + |
| 67 | + // Users should exist now |
| 68 | + expect(user).not.to.be.null; |
| 69 | + expect(sameUser).not.to.be.null; |
| 70 | + // Id should be filled automatically |
| 71 | + expect(sameUser.id).not.to.be.null; |
| 72 | + // Id, externalId and name should be the same |
| 73 | + expect(user.id).to.equal(sameUser.id); |
| 74 | + expect(user.externalId).to.equal(sameUser.externalId); |
| 75 | + expect(user.name).to.equal(sameUser.name); |
| 76 | + }); |
| 77 | +}; |
0 commit comments