| 
									
										
										
										
											2022-01-25 11:34:16 +01:00
										 |  |  | import { readFileSync } from 'fs'; | 
					
						
							|  |  |  | import { getMetaData } from './get-project-path-metadata'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  | jest.mock('fs', () => { | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     readFileSync: jest.fn() | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const mockPath = '/mock/path'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('getMetaData helper', () => { | 
					
						
							|  |  |  |   it('should process requested file', () => { | 
					
						
							| 
									
										
										
										
											2022-01-25 11:34:16 +01:00
										 |  |  |     // @ts-expect-error - readFileSync is mocked
 | 
					
						
							|  |  |  |     // eslint-disable-next-line @typescript-eslint/no-unsafe-call
 | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  |     readFileSync.mockImplementation(() => '{"name": "Test Project"}'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const expected = { | 
					
						
							|  |  |  |       name: 'Test Project' | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(getMetaData(mockPath)).toEqual(expected); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should throw if file is not found', () => { | 
					
						
							| 
									
										
										
										
											2022-01-25 11:34:16 +01:00
										 |  |  |     // @ts-expect-error - readFileSync is mocked
 | 
					
						
							|  |  |  |     // eslint-disable-next-line @typescript-eslint/no-unsafe-call
 | 
					
						
							| 
									
										
										
										
											2021-07-06 19:22:12 -05:00
										 |  |  |     readFileSync.mockImplementation(() => { | 
					
						
							|  |  |  |       throw new Error(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(() => { | 
					
						
							|  |  |  |       getMetaData(mockPath); | 
					
						
							|  |  |  |     }).toThrowError(new Error(`No _meta.json file exists at ${mockPath}`)); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |