2016-08-02 5 views
-1

토큰 및 기타 정보가 포함 된 json 개체를 반환하는 인증 끝점에 자격 증명이있는 http 게시를 수행하는 로그인 구성 요소를 조롱하려고합니다. "500 내부 서버 오류"응답을 얻기InMemoryBackendService 오류 collection.reduce가 함수가 아닙니다.

, 추가 검사에 여기

error:"collection.reduce is not a function" 

내 종자 데이터 파일입니다 ... 응답의 본문에 추가 정보를 볼 수

export class AppData { 
    createDb() { 
    let auth = { 
     access_token: '2YotnFZFEjr1zCsicMWpAA', 
     token_type: 'bearer', 
     expires_in: 3500 
    }; 
    return {auth}; 
    } 
} 

auth.service.ts

public authenticateUser(user:string, pass:string):Promise<AuthResponseModel> { 


    // TODO: Hit auth endpoint 
    let authUrl = 'app/auth'; 
    let headers = new Headers({ 'Content-Type': 'application/json' }); 
    let options = new RequestOptions({ headers: headers }); 
    let body = JSON.stringify({ username: user, password: pass}); 

    return this.http.post(authUrl, body, options) 
     .toPromise() 
     .then((res: Response) => { 
      let body = res.json(); 
      return body.data || { }; 
     },(reason:any) => { 
      console.log('authenticateUser() error %o ', reason); 
      return Promise.reject(reason); 

     }) 
     .catch(this.handleError); 


} 

답변

0

InMemoryBackendService는 컬렉션과 함께 작동합니다. 따라서 간단한 CRUD 엔드 포인트가 아닌 다른 서비스를 조롱하는 것은 상당히 쓸모가 없습니다.

관련 문제