|
| 1 | +import { syncProjects } from './daff'; |
| 2 | + |
| 3 | +const buildAngularJson = (projectName: string) => ({ |
| 4 | + version: 1, |
| 5 | + projects: { |
| 6 | + [projectName]: { |
| 7 | + architect: { |
| 8 | + build: { |
| 9 | + configurations: { |
| 10 | + production: {}, |
| 11 | + }, |
| 12 | + }, |
| 13 | + }, |
| 14 | + }, |
| 15 | + }, |
| 16 | +}); |
| 17 | + |
| 18 | +describe('syncProjects', () => { |
| 19 | + const projectName = 'app'; |
| 20 | + |
| 21 | + it('writes the magento condition derived from daff.json', () => { |
| 22 | + const angular = buildAngularJson(projectName); |
| 23 | + const daff = { projects: { [projectName]: { drivers: { magento: '2.4.5' }}}}; |
| 24 | + |
| 25 | + syncProjects(daff, angular); |
| 26 | + |
| 27 | + expect( |
| 28 | + angular.projects[projectName].architect.build.configurations.production, |
| 29 | + ).toEqual(<any>{ conditions: ['magento-2.4.5']}); |
| 30 | + }); |
| 31 | + |
| 32 | + it('overwrites an existing conditions array', () => { |
| 33 | + const angular = buildAngularJson(projectName); |
| 34 | + (<any>angular.projects[projectName].architect.build.configurations.production).conditions = [ |
| 35 | + 'magento-2.4.1', |
| 36 | + 'some-other-condition', |
| 37 | + ]; |
| 38 | + const daff = { projects: { [projectName]: { drivers: { magento: '2.4.5' }}}}; |
| 39 | + |
| 40 | + syncProjects(daff, angular); |
| 41 | + |
| 42 | + const conditions = (<any>angular.projects[projectName].architect.build.configurations.production).conditions; |
| 43 | + expect(conditions).toEqual(['magento-2.4.5']); |
| 44 | + }); |
| 45 | + |
| 46 | + it('throws when a project is missing a driver version', () => { |
| 47 | + const angular = buildAngularJson(projectName); |
| 48 | + const daff = { projects: { [projectName]: { drivers: {}}}}; |
| 49 | + |
| 50 | + expect(() => syncProjects(daff, angular)).toThrowError( |
| 51 | + /missing a driver version/, |
| 52 | + ); |
| 53 | + }); |
| 54 | + |
| 55 | + it('throws when the project is absent from angular.json', () => { |
| 56 | + const angular = buildAngularJson('other'); |
| 57 | + const daff = { projects: { [projectName]: { drivers: { magento: '2.4.5' }}}}; |
| 58 | + |
| 59 | + expect(() => syncProjects(daff, angular)).toThrowError( |
| 60 | + /not found in angular.json/, |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it('creates intermediate architect/build/configurations objects when missing', () => { |
| 65 | + const angular = { projects: { [projectName]: {}}}; |
| 66 | + const daff = { projects: { [projectName]: { drivers: { magento: '2.4.5' }}}}; |
| 67 | + |
| 68 | + syncProjects(daff, angular); |
| 69 | + |
| 70 | + expect( |
| 71 | + (<any>angular).projects[projectName].architect.build.configurations.production.conditions, |
| 72 | + ).toEqual(['magento-2.4.5']); |
| 73 | + }); |
| 74 | + |
| 75 | + it('is a no-op when daff.json has no projects', () => { |
| 76 | + const angular = buildAngularJson(projectName); |
| 77 | + const daff = {}; |
| 78 | + |
| 79 | + expect(() => syncProjects(daff, angular)).not.toThrow(); |
| 80 | + expect( |
| 81 | + (<any>angular.projects[projectName].architect.build.configurations.production).conditions, |
| 82 | + ).toBeUndefined(); |
| 83 | + }); |
| 84 | +}); |
0 commit comments