it('should call validatePassword', () => {
service.validatePassword('foo').subscribe();
- const req = httpTesting.expectOne('api/user/validate_password?password=foo');
+ const req = httpTesting.expectOne('api/user/validate_password');
expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual({ password: 'foo', old_password: null, username: null });
});
it('should call validatePassword (incl. name)', () => {
service.validatePassword('foo_bar', 'bar').subscribe();
- const req = httpTesting.expectOne('api/user/validate_password?password=foo_bar&username=bar');
+ const req = httpTesting.expectOne('api/user/validate_password');
expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual({ password: 'foo_bar', username: 'bar', old_password: null });
});
it('should call validatePassword (incl. old password)', () => {
service.validatePassword('foo', null, 'foo').subscribe();
- const req = httpTesting.expectOne('api/user/validate_password?password=foo&old_password=foo');
+ const req = httpTesting.expectOne('api/user/validate_password');
expect(req.request.method).toBe('POST');
+ expect(req.request.body).toEqual({ password: 'foo', old_password: 'foo', username: null });
});
});
-import { HttpClient, HttpParams } from '@angular/common/http';
+import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, of as observableOf } from 'rxjs';
}
validatePassword(password: string, username: string = null, oldPassword: string = null) {
- let params = new HttpParams();
- params = params.append('password', password);
- if (username) {
- params = params.append('username', username);
- }
- if (oldPassword) {
- params = params.append('old_password', oldPassword);
- }
- return this.http.post('api/user/validate_password', null, { params });
+ return this.http.post('api/user/validate_password', {
+ password: password,
+ username: username,
+ old_password: oldPassword
+ });
}
}