|
2 | 2 | import test from 'ava'; |
3 | 3 | import type { Provisioner } from '@openfn/lexicon/lightning'; |
4 | 4 | import { Project } from '../src/Project'; |
5 | | -import generateWorkflow from '../src/gen/generator'; |
| 5 | +import generateWorkflow, { generateProject } from '../src/gen/generator'; |
6 | 6 |
|
7 | 7 | // TODO move to fixtures and re-use? |
8 | 8 | // Or use util function instead? |
@@ -154,3 +154,34 @@ test('should return UUIDs for everything', (t) => { |
154 | 154 | }, |
155 | 155 | }); |
156 | 156 | }); |
| 157 | + |
| 158 | +test('incompatible-merge: should throw error when merge is incompatible', (t) => { |
| 159 | + const source = generateWorkflow('trigger-x'); |
| 160 | + source.pushHistory(source.getVersionHash()); |
| 161 | + const target = generateWorkflow('trigger-y'); |
| 162 | + target.pushHistory(target.getVersionHash()); |
| 163 | + |
| 164 | + t.false(source.canMergeInto(target)); |
| 165 | + |
| 166 | + const sourceProject = new Project({ workflows: [source] }); |
| 167 | + const targetProject = new Project({ workflows: [target] }); |
| 168 | + t.throws(() => Project.merge(sourceProject, targetProject), { |
| 169 | + message: `The below workflows can't be merged directly without losing data\nWorkflow → Workflow\nPass --force to force the merge anyway`, |
| 170 | + }); |
| 171 | +}); |
| 172 | + |
| 173 | +test('incompatible-merge-force: should ignore incompatiblity and merge when forced', (t) => { |
| 174 | + // same as the above test with force |
| 175 | + const source = generateWorkflow('trigger-x'); |
| 176 | + source.pushHistory(source.getVersionHash()); |
| 177 | + const target = generateWorkflow('trigger-y'); |
| 178 | + target.pushHistory(target.getVersionHash()); |
| 179 | + |
| 180 | + t.false(source.canMergeInto(target)); |
| 181 | + |
| 182 | + const sourceProject = new Project({ workflows: [source] }); |
| 183 | + const targetProject = new Project({ workflows: [target] }); |
| 184 | + t.notThrows(() => |
| 185 | + Project.merge(sourceProject, targetProject, { force: true }) |
| 186 | + ); |
| 187 | +}); |
0 commit comments