|
| 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 | +import AdmZip from 'adm-zip'; |
| 7 | + |
| 8 | +export const mockCustomTutorialId = 'a77b23c1-7816-4ea4-b61f-d37795a0f805-ct-id'; |
| 9 | + |
| 10 | +export const mockCustomTutorialId2 = 'a77b23c1-7816-4ea4-b61f-d37795a0f805-ct-id-2'; |
| 11 | + |
| 12 | +export const mockCustomTutorialTmpPath = '/tmp/path'; |
| 13 | + |
| 14 | +export const mockCustomTutorialsHttpLink = 'https://somesime.com/archive.zip'; |
| 15 | + |
| 16 | +export const mockCustomTutorial = Object.assign(new CustomTutorial(), { |
| 17 | + id: mockCustomTutorialId, |
| 18 | + name: 'custom tutorial', |
| 19 | + createdAt: new Date(), |
| 20 | +}); |
| 21 | + |
| 22 | +export const mockCustomTutorialEntity = Object.assign(new CustomTutorialEntity(), { |
| 23 | + ...mockCustomTutorial, |
| 24 | +}); |
| 25 | + |
| 26 | +export const mockCustomTutorial2 = Object.assign(new CustomTutorial(), { |
| 27 | + id: mockCustomTutorialId2, |
| 28 | + name: 'custom tutorial 2', |
| 29 | + link: mockCustomTutorialsHttpLink, |
| 30 | + createdAt: new Date(), |
| 31 | +}); |
| 32 | + |
| 33 | +export const mockCustomTutorialZipFile = Object.assign(new MemoryStoredFile(), { |
| 34 | + size: 100, |
| 35 | + buffer: Buffer.from('zip-content', 'utf8'), |
| 36 | +}); |
| 37 | + |
| 38 | +export const mockCustomTutorialZipFileAxiosResponse = { |
| 39 | + data: mockCustomTutorialZipFile.buffer, |
| 40 | +}; |
| 41 | + |
| 42 | +export const mockCustomTutorialAdmZipEntry = { |
| 43 | + entryName: 'somefolder/info.md', |
| 44 | +} as AdmZip.IZipEntry; |
| 45 | + |
| 46 | +export const mockCustomTutorialMacosxAdmZipEntry = { |
| 47 | + entryName: '__MACOSX/info.md', |
| 48 | +} as AdmZip.IZipEntry; |
| 49 | + |
| 50 | +export const mockUploadCustomTutorialDto = Object.assign(new UploadCustomTutorialDto(), { |
| 51 | + file: mockCustomTutorialZipFile, |
| 52 | +}); |
| 53 | + |
| 54 | +export const mockUploadCustomTutorialExternalLinkDto = Object.assign(new UploadCustomTutorialDto(), { |
| 55 | + link: mockCustomTutorialsHttpLink, |
| 56 | +}); |
| 57 | + |
| 58 | +export const mockCustomTutorialManifestJson = { |
| 59 | + type: CustomTutorialManifestType.Group, |
| 60 | + id: mockCustomTutorialId, |
| 61 | + label: mockCustomTutorial.name, |
| 62 | + children: [ |
| 63 | + { |
| 64 | + type: 'group', |
| 65 | + id: 'ct-folder-1', |
| 66 | + label: 'ct-folder-1', |
| 67 | + children: [ |
| 68 | + { |
| 69 | + type: CustomTutorialManifestType.Group, |
| 70 | + id: 'ct-sub-folder-1', |
| 71 | + label: 'ct-sub-folder-1', |
| 72 | + children: [ |
| 73 | + { |
| 74 | + type: CustomTutorialManifestType.InternalLink, |
| 75 | + id: 'introduction', |
| 76 | + label: 'introduction', |
| 77 | + args: { |
| 78 | + path: '/ct-folder-1/ct-sub-folder-1/introduction.md', |
| 79 | + }, |
| 80 | + }, |
| 81 | + { |
| 82 | + type: CustomTutorialManifestType.InternalLink, |
| 83 | + id: 'working-with-hashes', |
| 84 | + label: 'working-with-hashes', |
| 85 | + args: { |
| 86 | + path: '/ct-folder-1/ct-sub-folder-1/working-with-hashes.md', |
| 87 | + }, |
| 88 | + }, |
| 89 | + ], |
| 90 | + }, |
| 91 | + { |
| 92 | + type: CustomTutorialManifestType.Group, |
| 93 | + id: 'ct-sub-folder-2', |
| 94 | + label: 'ct-sub-folder-2', |
| 95 | + children: [ |
| 96 | + { |
| 97 | + type: CustomTutorialManifestType.InternalLink, |
| 98 | + id: 'introduction', |
| 99 | + label: 'introduction', |
| 100 | + args: { |
| 101 | + path: '/ct-folder-1/ct-sub-folder-2/introduction.md', |
| 102 | + }, |
| 103 | + }, |
| 104 | + { |
| 105 | + type: CustomTutorialManifestType.InternalLink, |
| 106 | + id: 'working-with-graphs', |
| 107 | + label: 'working-with-graphs', |
| 108 | + args: { |
| 109 | + path: '/ct-folder-1/ct-sub-folder-2/working-with-graphs.md', |
| 110 | + }, |
| 111 | + }, |
| 112 | + ], |
| 113 | + }, |
| 114 | + ], |
| 115 | + }, |
| 116 | + ], |
| 117 | +}; |
| 118 | + |
| 119 | +export const mockCustomTutorialManifest = { |
| 120 | + ...mockCustomTutorialManifestJson, |
| 121 | + type: CustomTutorialManifestType.Group, |
| 122 | + id: mockCustomTutorialId, |
| 123 | + label: mockCustomTutorial.name, |
| 124 | + _actions: mockCustomTutorial.actions, |
| 125 | + _path: mockCustomTutorial.path, |
| 126 | +}; |
| 127 | + |
| 128 | +export const mockCustomTutorialManifest2 = { |
| 129 | + type: CustomTutorialManifestType.Group, |
| 130 | + id: mockCustomTutorialId2, |
| 131 | + label: mockCustomTutorial2.name, |
| 132 | + _actions: mockCustomTutorial2.actions, |
| 133 | + _path: mockCustomTutorial2.path, |
| 134 | + children: [mockCustomTutorialManifestJson], |
| 135 | +}; |
| 136 | + |
| 137 | +export const globalCustomTutorialManifest = { |
| 138 | + type: CustomTutorialManifestType.Group, |
| 139 | + id: 'custom-tutorials', |
| 140 | + label: 'MY TUTORIALS', |
| 141 | + _actions: [CustomTutorialActions.CREATE], |
| 142 | + args: { |
| 143 | + withBorder: true, |
| 144 | + initialIsOpen: true, |
| 145 | + }, |
| 146 | + children: [ |
| 147 | + mockCustomTutorialManifest, |
| 148 | + mockCustomTutorialManifest2, |
| 149 | + ], |
| 150 | +}; |
| 151 | + |
| 152 | +export const mockCustomTutorialFsProvider = jest.fn(() => ({ |
| 153 | + unzipFromMemoryStoredFile: jest.fn().mockResolvedValue(mockCustomTutorialTmpPath), |
| 154 | + unzipFromExternalLink: jest.fn().mockResolvedValue(mockCustomTutorialTmpPath), |
| 155 | + unzipToTmpFolder: jest.fn().mockResolvedValue(mockCustomTutorialTmpPath), |
| 156 | + moveFolder: jest.fn(), |
| 157 | + removeFolder: jest.fn(), |
| 158 | +})); |
| 159 | + |
| 160 | +export const mockCustomTutorialManifestProvider = jest.fn(() => ({ |
| 161 | + getOriginalManifestJson: jest.fn().mockResolvedValue(mockCustomTutorialManifestJson), |
| 162 | + getManifestJson: jest.fn().mockResolvedValue(mockCustomTutorialManifestJson), |
| 163 | + generateTutorialManifest: jest.fn().mockResolvedValue(mockCustomTutorialManifest), |
| 164 | + isOriginalManifestExists: jest.fn().mockResolvedValue(true), |
| 165 | +})); |
| 166 | + |
| 167 | +export const mockCustomTutorialRepository = jest.fn(() => ({ |
| 168 | + get: jest.fn().mockResolvedValue(mockCustomTutorial), |
| 169 | + create: jest.fn().mockResolvedValue(mockCustomTutorial), |
| 170 | + delete: jest.fn(), |
| 171 | + list: jest.fn().mockResolvedValue([ |
| 172 | + mockCustomTutorial, |
| 173 | + mockCustomTutorial2, |
| 174 | + ]), |
| 175 | +})); |
| 176 | + |
| 177 | +export const mockCustomTutorialAnalytics = jest.fn(() => ({ |
| 178 | + sendImportSucceeded: jest.fn(), |
| 179 | + sendImportFailed: jest.fn(), |
| 180 | +})); |
0 commit comments