|
| 1 | +import { CustomTutorial, CustomTutorialActions } from 'src/modules/custom-tutorial/models/custom-tutorial'; |
| 2 | +import { CustomTutorialEntity } from 'src/modules/custom-tutorial/entities/custom-tutorial.entity'; |
| 3 | +import { CustomTutorialManifestType } from 'src/modules/custom-tutorial/models/custom-tutorial.manifest'; |
| 4 | +import { MemoryStoredFile } from 'nestjs-form-data'; |
| 5 | +import { UploadCustomTutorialDto } from 'src/modules/custom-tutorial/dto/upload.custom-tutorial.dto'; |
| 6 | + |
| 7 | +export const mockCustomTutorialId = 'a77b23c1-7816-4ea4-b61f-d37795a0f805-ct-id'; |
| 8 | + |
| 9 | +export const mockCustomTutorialId2 = 'a77b23c1-7816-4ea4-b61f-d37795a0f805-ct-id-2'; |
| 10 | + |
| 11 | +export const mockCustomTutorialTmpPath = '/tmp/path'; |
| 12 | + |
| 13 | +export const mockCustomTutorial = Object.assign(new CustomTutorial(), { |
| 14 | + id: mockCustomTutorialId, |
| 15 | + name: 'custom tutorial', |
| 16 | + createdAt: new Date(), |
| 17 | +}); |
| 18 | + |
| 19 | +export const mockCustomTutorialEntity = Object.assign(new CustomTutorialEntity(), { |
| 20 | + ...mockCustomTutorial, |
| 21 | +}); |
| 22 | + |
| 23 | +export const mockCustomTutorial2 = Object.assign(new CustomTutorial(), { |
| 24 | + id: mockCustomTutorialId2, |
| 25 | + name: 'custom tutorial 2', |
| 26 | + createdAt: new Date(), |
| 27 | +}); |
| 28 | + |
| 29 | +export const mockCustomTutorialZipFile = Object.assign(new MemoryStoredFile(), { |
| 30 | + size: 100, |
| 31 | + buffer: Buffer.from('zip-content', 'utf8'), |
| 32 | +}); |
| 33 | + |
| 34 | +export const mockUploadCustomTutorialDto = Object.assign(new UploadCustomTutorialDto(), { |
| 35 | + name: mockCustomTutorial.name, |
| 36 | + file: mockCustomTutorialZipFile, |
| 37 | +}); |
| 38 | + |
| 39 | +export const mockCustomTutorialManifestManifestJson = { |
| 40 | + 'ct-folder-1': { |
| 41 | + type: 'group', |
| 42 | + id: 'ct-folder-1', |
| 43 | + label: 'ct-folder-1', |
| 44 | + // args: { |
| 45 | + // withBorder: true, |
| 46 | + // initialIsOpen: true, |
| 47 | + // }, |
| 48 | + children: { |
| 49 | + 'ct-sub-folder-1': { |
| 50 | + type: CustomTutorialManifestType.Group, |
| 51 | + id: 'ct-sub-folder-1', |
| 52 | + label: 'ct-sub-folder-1', |
| 53 | + // args: { |
| 54 | + // initialIsOpen: false, |
| 55 | + // }, |
| 56 | + children: { |
| 57 | + introduction: { |
| 58 | + type: CustomTutorialManifestType.InternalLink, |
| 59 | + id: 'introduction', |
| 60 | + label: 'introduction', |
| 61 | + args: { |
| 62 | + path: '/ct-folder-1/ct-sub-folder-1/introduction.md', |
| 63 | + }, |
| 64 | + }, |
| 65 | + 'working-with-hashes': { |
| 66 | + type: CustomTutorialManifestType.InternalLink, |
| 67 | + id: 'working-with-hashes', |
| 68 | + label: 'working-with-hashes', |
| 69 | + args: { |
| 70 | + path: '/ct-folder-1/ct-sub-folder-1/working-with-hashes.md', |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }, |
| 75 | + 'ct-sub-folder-2': { |
| 76 | + type: CustomTutorialManifestType.Group, |
| 77 | + id: 'ct-sub-folder-2', |
| 78 | + label: 'ct-sub-folder-2', |
| 79 | + // args: { |
| 80 | + // withBorder: true, |
| 81 | + // initialIsOpen: false, |
| 82 | + // }, |
| 83 | + children: { |
| 84 | + introduction: { |
| 85 | + type: CustomTutorialManifestType.InternalLink, |
| 86 | + id: 'introduction', |
| 87 | + label: 'introduction', |
| 88 | + args: { |
| 89 | + path: '/ct-folder-1/ct-sub-folder-2/introduction.md', |
| 90 | + }, |
| 91 | + }, |
| 92 | + 'working-with-graphs': { |
| 93 | + type: CustomTutorialManifestType.InternalLink, |
| 94 | + id: 'working-with-graphs', |
| 95 | + label: 'working-with-graphs', |
| 96 | + args: { |
| 97 | + path: '/ct-folder-1/ct-sub-folder-2/working-with-graphs.md', |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | +}; |
| 105 | + |
| 106 | +export const mockCustomTutorialManifestManifest = { |
| 107 | + type: CustomTutorialManifestType.Group, |
| 108 | + id: mockCustomTutorialId, |
| 109 | + label: mockCustomTutorial.name, |
| 110 | + _actions: mockCustomTutorial.actions, |
| 111 | + _path: mockCustomTutorial.path, |
| 112 | + children: mockCustomTutorialManifestManifestJson, |
| 113 | +}; |
| 114 | + |
| 115 | +export const mockCustomTutorialManifestManifest2 = { |
| 116 | + type: CustomTutorialManifestType.Group, |
| 117 | + id: mockCustomTutorialId2, |
| 118 | + label: mockCustomTutorial2.name, |
| 119 | + _actions: mockCustomTutorial2.actions, |
| 120 | + _path: mockCustomTutorial2.path, |
| 121 | + children: mockCustomTutorialManifestManifestJson, |
| 122 | +}; |
| 123 | + |
| 124 | +export const globalCustomTutorialManifest = { |
| 125 | + 'custom-tutorials': { |
| 126 | + type: CustomTutorialManifestType.Group, |
| 127 | + id: 'custom-tutorials', |
| 128 | + label: 'My Tutorials', |
| 129 | + _actions: [CustomTutorialActions.CREATE], |
| 130 | + args: { |
| 131 | + withBorder: true, |
| 132 | + initialIsOpen: true, |
| 133 | + }, |
| 134 | + children: { |
| 135 | + [mockCustomTutorialManifestManifest.id]: mockCustomTutorialManifestManifest, |
| 136 | + [mockCustomTutorialManifestManifest2.id]: mockCustomTutorialManifestManifest2, |
| 137 | + }, |
| 138 | + }, |
| 139 | +}; |
| 140 | + |
| 141 | +export const mockCustomTutorialFsProvider = jest.fn(() => ({ |
| 142 | + unzipToTmpFolder: jest.fn().mockResolvedValue(mockCustomTutorialTmpPath), |
| 143 | + moveFolder: jest.fn(), |
| 144 | + removeFolder: jest.fn(), |
| 145 | +})); |
| 146 | + |
| 147 | +export const mockCustomTutorialManifestProvider = jest.fn(() => ({ |
| 148 | + getManifestJson: jest.fn().mockResolvedValue(mockCustomTutorialManifestManifestJson), |
| 149 | + generateTutorialManifest: jest.fn().mockResolvedValue(mockCustomTutorialManifestManifest), |
| 150 | +})); |
| 151 | + |
| 152 | +export const mockCustomTutorialRepository = jest.fn(() => ({ |
| 153 | + get: jest.fn().mockResolvedValue(mockCustomTutorial), |
| 154 | + create: jest.fn().mockResolvedValue(mockCustomTutorial), |
| 155 | + delete: jest.fn(), |
| 156 | + list: jest.fn().mockResolvedValue([ |
| 157 | + mockCustomTutorial, |
| 158 | + mockCustomTutorial2, |
| 159 | + ]), |
| 160 | +})); |
0 commit comments