|
4 | 4 | MAX_UPLOAD_RETRY_COUNT, |
5 | 5 | MINIMUM_THEME_ASSETS, |
6 | 6 | uploadTheme, |
| 7 | + updateUploadErrors, |
7 | 8 | } from './theme-uploader.js' |
8 | 9 | import {fakeThemeFileSystem} from './theme-fs/theme-fs-mock-factory.js' |
9 | 10 | import {bulkUploadThemeAssets, deleteThemeAsset} from '@shopify/cli-kit/node/themes/api' |
@@ -602,3 +603,83 @@ describe('theme-uploader', () => { |
602 | 603 | ) |
603 | 604 | }) |
604 | 605 | }) |
| 606 | + |
| 607 | +describe('updateUploadErrors', () => { |
| 608 | + test('should clear error for successful upload', () => { |
| 609 | + // Given |
| 610 | + const themeFileSystem = fakeThemeFileSystem('tmp', new Map()) |
| 611 | + const result: Result = { |
| 612 | + key: 'file1.liquid', |
| 613 | + success: true, |
| 614 | + errors: {}, |
| 615 | + operation: Operation.Upload, |
| 616 | + asset: {key: 'file1.liquid', checksum: 'abc'}, |
| 617 | + } |
| 618 | + |
| 619 | + // Pre-existing error that should be cleared |
| 620 | + themeFileSystem.uploadErrors.set('file1.liquid', ['Old error']) |
| 621 | + |
| 622 | + // When |
| 623 | + updateUploadErrors(result, themeFileSystem) |
| 624 | + |
| 625 | + // Then |
| 626 | + expect(themeFileSystem.uploadErrors.has('file1.liquid')).toBe(false) |
| 627 | + }) |
| 628 | + |
| 629 | + test('should set error for failed upload', () => { |
| 630 | + // Given |
| 631 | + const themeFileSystem = fakeThemeFileSystem('tmp', new Map()) |
| 632 | + const result: Result = { |
| 633 | + key: 'file1.liquid', |
| 634 | + success: false, |
| 635 | + errors: {asset: ['Upload failed']}, |
| 636 | + operation: Operation.Upload, |
| 637 | + asset: {key: 'file1.liquid', checksum: 'abc'}, |
| 638 | + } |
| 639 | + |
| 640 | + // When |
| 641 | + updateUploadErrors(result, themeFileSystem) |
| 642 | + |
| 643 | + // Then |
| 644 | + expect(themeFileSystem.uploadErrors.get('file1.liquid')).toEqual(['Upload failed']) |
| 645 | + }) |
| 646 | + |
| 647 | + test('should set default error when no specific error provided', () => { |
| 648 | + // Given |
| 649 | + const themeFileSystem = fakeThemeFileSystem('tmp', new Map()) |
| 650 | + const result: Result = { |
| 651 | + key: 'file1.liquid', |
| 652 | + success: false, |
| 653 | + errors: {}, |
| 654 | + operation: Operation.Upload, |
| 655 | + asset: {key: 'file1.liquid', checksum: 'abc'}, |
| 656 | + } |
| 657 | + |
| 658 | + // When |
| 659 | + updateUploadErrors(result, themeFileSystem) |
| 660 | + |
| 661 | + // Then |
| 662 | + expect(themeFileSystem.uploadErrors.get('file1.liquid')).toEqual(['Response was not successful.']) |
| 663 | + }) |
| 664 | + |
| 665 | + test('should update existing error', () => { |
| 666 | + // Given |
| 667 | + const themeFileSystem = fakeThemeFileSystem('tmp', new Map()) |
| 668 | + const result: Result = { |
| 669 | + key: 'file1.liquid', |
| 670 | + success: false, |
| 671 | + errors: {asset: ['New error']}, |
| 672 | + operation: Operation.Upload, |
| 673 | + asset: {key: 'file1.liquid', checksum: 'abc'}, |
| 674 | + } |
| 675 | + |
| 676 | + // Pre-existing error that should be updated |
| 677 | + themeFileSystem.uploadErrors.set('file1.liquid', ['Old error']) |
| 678 | + |
| 679 | + // When |
| 680 | + updateUploadErrors(result, themeFileSystem) |
| 681 | + |
| 682 | + // Then |
| 683 | + expect(themeFileSystem.uploadErrors.get('file1.liquid')).toEqual(['New error']) |
| 684 | + }) |
| 685 | +}) |
0 commit comments