| 
									
										
										
										
											2018-09-30 20:34:01 +01:00
										 |  |  | /* global describe it expect beforeEach */ | 
					
						
							|  |  |  | const mockAST = require('./fixtures/challenge-html-ast.json'); | 
					
						
							|  |  |  | const solutionToData = require('./solution-to-data'); | 
					
						
							| 
									
										
										
										
											2020-07-14 14:20:51 +02:00
										 |  |  | const { isObject } = require('lodash'); | 
					
						
							| 
									
										
										
										
											2018-09-30 20:34:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('challengeSeed-to-data plugin', () => { | 
					
						
							|  |  |  |   const plugin = solutionToData(); | 
					
						
							|  |  |  |   let file = { data: {} }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							|  |  |  |     file = { data: {} }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('returns a function', () => { | 
					
						
							|  |  |  |     expect(typeof plugin).toEqual('function'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('adds a `solutions` property to `file.data`', () => { | 
					
						
							|  |  |  |     plugin(mockAST, file); | 
					
						
							|  |  |  |     expect('solutions' in file.data).toBe(true); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('ensures that the `solutions` property is an array', () => { | 
					
						
							|  |  |  |     plugin(mockAST, file); | 
					
						
							|  |  |  |     expect(Array.isArray(file.data.solutions)).toBe(true); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 14:20:51 +02:00
										 |  |  |   it('each entry in the `solutions` array is an object', () => { | 
					
						
							| 
									
										
										
										
											2018-09-30 20:34:01 +01:00
										 |  |  |     plugin(mockAST, file); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-14 14:20:51 +02:00
										 |  |  |     expect(file.data.solutions.every(el => isObject(el))).toBe(true); | 
					
						
							| 
									
										
										
										
											2018-09-30 20:34:01 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should have an output to match the snapshot', () => { | 
					
						
							|  |  |  |     plugin(mockAST, file); | 
					
						
							|  |  |  |     expect(file.data).toMatchSnapshot(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |