How to use the @angular/common/http.HttpResponse function in @angular/common

To help you get started, we’ve selected a few @angular/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Ninja-Squad / globe42 / frontend / src / app / cities-upload / cities-upload.component.spec.ts View on Github external
// emit last progress events
      tickSeconds(10);
      fakeEvents.next({
        type: HttpEventType.UploadProgress,
        loaded: 10,
        total: 10
      });

      expect(component.progress).toBe(10 / 30);
      expect(component.status).toBe('processing');

      tickSeconds(15);
      expect(component.progress).toBe(25 / 30);

      // emit response and complete
      fakeEvents.next(new HttpResponse());
      fakeEvents.complete();
      expect(component.progress).toBe(1);
      expect(component.status).toBe('done');

      // let the fake event observable a chance to realize that the processing is done
      tickSeconds(1);
    })
  );
github cornflourblue / angular-6-jwt-authentication-example / src / app / _helpers / fake-backend.ts View on Github external
firstName: testUser.firstName,
                        lastName: testUser.lastName,
                        token: 'fake-jwt-token'
                    };
                    return of(new HttpResponse({ status: 200, body }));
                } else {
                    // else return 400 bad request
                    return throwError({ error: { message: 'Username or password is incorrect' } });
                }
            }

            // get users
            if (request.url.endsWith('/users') && request.method === 'GET') {
                // check for fake auth token in header and return users if valid, this security is implemented server side in a real application
                if (request.headers.get('Authorization') === 'Bearer fake-jwt-token') {
                    return of(new HttpResponse({ status: 200, body: [testUser] }));
                } else {
                    // return 401 not authorised if token is null or invalid
                    return throwError({ error: { message: 'Unauthorised' } });
                }
            }

            // pass through any requests not handled above
            return next.handle(request);
            
        }))
github fulls1z3 / ngx-auth / packages / @ngx-auth / core / testing / mocks / backend-interceptor.mock.ts View on Github external
const testUser: any = {
        username: 'valid',
        password: 'valid'
      };

      const body = JSON.parse(request.body);

      if (body.username === testUser.username && body.password === testUser.password) {
        return observableOf(
          new HttpResponse({
            status: 200,
            body: { token: 'fake-jwt-token' }
          })
        );
      } else {
        return observableOf(new HttpResponse({ status: 401 }));
      }
    }

    return next.handle(request);
  }
}
github FabianGosebrink / ASPNETCore-Angular-Ngrx / client / src / testing / foodServiceMock.ts View on Github external
return Observable.create((observer: any) => {
      const itemToRemove = this.internalFoodList.find(x => x.id === id);
      const indexToRemove = this.internalFoodList.indexOf(itemToRemove);
      this.internalFoodList.splice(indexToRemove, 1);

      observer.next(
        new HttpResponse({
          status: 204
        })
      );
      observer.complete();
    });
  }
github IgniteUI / igniteui-cli / templates / angular / igx-ts / projects / side-nav-auth / files / src / app / authentication / services / fake-backend.service.ts View on Github external
registerHandle(newUser: StorageUser, update = false) {
        const duplicateUser = this.users.find(user => user.email === newUser.email);
        if (duplicateUser && !update) {
            return throwError({ error: { message: 'Account with email "' + newUser.email + '" already exists' } });
        }
        if (update && duplicateUser) {
            Object.assign(duplicateUser, newUser);
        } else {
            this.users.push(newUser);
        }
        localStorage.setItem('users', JSON.stringify(this.users));

        const body = this.getUserJWT(newUser);

        return of(new HttpResponse({ status: 200, body: this.generateToken(body) }));
    }
github reyesoft / ngx-jsonapi / src / services / path-collection-builder.spec.ts View on Github external
public handle(req: HttpRequest): Observable> {
        let subject = new BehaviorSubject(new HttpResponse());

        return subject.asObservable();
    }
}
github isaacplmann / ngrx-query / src / demo / mockServer.ts View on Github external
}));
    } else if (this.state === SERVER_STATE.UNAUTHORIZED) {
      return of(new HttpResponse({
        status: 401,
        body: { error: 'Unauthorized'},
      }));
    } else if (this.state === SERVER_STATE.ERROR) {
      return of(new HttpResponse({
        status: 500,
        body: { error: 'Internal server error'},
      }));
    }
    switch (method) {
      case RequestMethod.Get:
        if (Number.isInteger(id)) {
          return of(new HttpResponse({
            body: this.rangers.find(ranger => ranger.id === id),
            status: 200,
          }));
        } else {
          return of(new HttpResponse({
            body: this.rangers.map(ranger => ({ id: ranger.id, name: ranger.name })),
            status: 200,
          }));
        }
      case RequestMethod.Post:
        body.id = this.rangers.length;
        this.rangers.push(body);
        return of(new HttpResponse({
          body,
          status: 200,
        }));
github cornflourblue / angular-7-registration-login-example / src / app / _helpers / fake-backend.ts View on Github external
function ok(body?) {
            return of(new HttpResponse({ status: 200, body }))
        }