|
| 1 | +/** |
| 2 | + Copyright 2022 Jason Drake |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | + */ |
| 16 | +import {createSpyObj} from 'jest-createspyobj'; |
| 17 | +import {BaseService} from 'services/base-service'; |
| 18 | + |
| 19 | +describe('BaseService service test suite', () => { |
| 20 | + |
| 21 | + let http = createSpyObj('http', ['configure']); |
| 22 | + |
| 23 | + describe('_augmentModel', () => { |
| 24 | + let svc; |
| 25 | + beforeEach(() => { |
| 26 | + svc = new BaseService(http, {}); |
| 27 | + }); |
| 28 | + |
| 29 | + it('correctly added null or empty properties missing', () => { |
| 30 | + let newModel = { |
| 31 | + id: 56 |
| 32 | + } |
| 33 | + let m = { |
| 34 | + id: 56, |
| 35 | + condition: 2, |
| 36 | + purchased: '2022-01-12' |
| 37 | + }; |
| 38 | + svc._augmentModel(newModel, m); |
| 39 | + expect(newModel.purchased).toBeNull(); |
| 40 | + expect(newModel.condition).toBe(0); |
| 41 | + }); |
| 42 | + |
| 43 | + it('correctly adds missing arrays', () => { |
| 44 | + let newModel = { |
| 45 | + id: 56 |
| 46 | + } |
| 47 | + let m = { |
| 48 | + id: 56, |
| 49 | + catalogueNumbers: [{ |
| 50 | + id: 47 |
| 51 | + }] |
| 52 | + }; |
| 53 | + svc._augmentModel(newModel, m); |
| 54 | + expect(newModel.catalogueNumbers.length).toBe(0); |
| 55 | + }); |
| 56 | + |
| 57 | + it('correctly adds missing objects', () => { |
| 58 | + let newModel = { |
| 59 | + id: 56 |
| 60 | + } |
| 61 | + let m = { |
| 62 | + id: 56, |
| 63 | + activeCatalogueNumber: { |
| 64 | + id: 43 |
| 65 | + } |
| 66 | + }; |
| 67 | + svc._augmentModel(newModel, m); |
| 68 | + expect(newModel.activeCatalogueNumber).toStrictEqual({}); |
| 69 | + }); |
| 70 | + |
| 71 | + it('adds missing values in child objects', () => { |
| 72 | + let newModel = { |
| 73 | + id: 56, |
| 74 | + stampOwnerships: [{ |
| 75 | + id: 43 |
| 76 | + }] |
| 77 | + } |
| 78 | + let m = { |
| 79 | + id: 56, |
| 80 | + stampOwnerships: [{ |
| 81 | + id: 43, |
| 82 | + pricePaid: '2021-12-31', |
| 83 | + condition: 2 |
| 84 | + }] |
| 85 | + }; |
| 86 | + svc._augmentModel(newModel, m); |
| 87 | + expect(newModel.stampOwnerships.length).toBe(1); |
| 88 | + expect(newModel.stampOwnerships[0].id).toBe(43); |
| 89 | + expect(newModel.stampOwnerships[0].condition).toBe(0); |
| 90 | + expect(newModel.stampOwnerships[0].pricePaid).toBe(null); |
| 91 | + }); |
| 92 | + |
| 93 | + }); |
| 94 | +}); |
0 commit comments