| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  | import { ApiStatus } from 'wherehows-web/utils/api/shared'; | 
					
						
							|  |  |  | import { Response, faker } from 'ember-cli-mirage'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type StringOrNullOrUndefined = string | null | void; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const textContentHeader = { 'Content-Type': 'text/plain; charset=utf-8' }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Returns a config object for the config endpoint | 
					
						
							|  |  |  |  * @param {object} _schema the auth table / factory object | 
					
						
							|  |  |  |  * @param {requestBody} property on the request object passed in to mirage function handlers | 
					
						
							|  |  |  |  * @return {{status: ApiStatus, data: object}} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getAuth = (_schema: {}, { requestBody }: { requestBody: string }) => { | 
					
						
							| 
									
										
										
										
											2018-08-23 14:24:15 -07:00
										 |  |  |   const { username, password } = <{ username: StringOrNullOrUndefined; password: StringOrNullOrUndefined }>( | 
					
						
							|  |  |  |     JSON.parse(requestBody) | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!password) { | 
					
						
							|  |  |  |     return new Response(400, textContentHeader, 'Missing or invalid [credentials]'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (password === 'invalidPassword') { | 
					
						
							|  |  |  |     return new Response(401, textContentHeader, 'Invalid Password'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 14:24:15 -07:00
										 |  |  |   console.log('authentication successful'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 21:19:11 -08:00
										 |  |  |   return { | 
					
						
							|  |  |  |     status: ApiStatus.OK, | 
					
						
							|  |  |  |     data: { username, uuid: faker.random.uuid() } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export { getAuth }; |