Skip to content

Commit ce1e130

Browse files
Merge branch 'master' of github.com:neroniaky/angular-token
2 parents 21fcb10 + 044e516 commit ce1e130

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

projects/angular-token/src/lib/angular-token.service.spec.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,36 @@ describe('AngularTokenService', () => {
7272
passwordConfirmation: 'password'
7373
};
7474

75+
// Register test data
76+
const registerCustomFieldsData: RegisterData = {
77+
login: 'test@test.de',
78+
first_name: 'John',
79+
last_name: 'Doe',
80+
password: 'password',
81+
passwordConfirmation: 'password'
82+
};
83+
84+
const registerCustomFieldsDataOutput = {
85+
email: 'test@test.de',
86+
first_name: 'John',
87+
last_name: 'Doe',
88+
password: 'password',
89+
password_confirmation: 'password',
90+
confirm_success_url: window.location.href
91+
};
92+
7593
const registerDataOutput = {
7694
email: 'test@test.de',
7795
password: 'password',
78-
password_confirmation: 'password'
96+
password_confirmation: 'password',
97+
confirm_success_url: window.location.href
7998
};
8099

81100
const registerCustomDataOutput = {
82101
username: 'test@test.de',
83102
password: 'password',
84-
password_confirmation: 'password'
103+
password_confirmation: 'password',
104+
confirm_success_url: window.location.href
85105
};
86106

87107
// Update password data
@@ -236,16 +256,31 @@ describe('AngularTokenService', () => {
236256
});
237257
});
238258

239-
it('registerAccount should POST data', () => {
259+
describe('registerAccount should POST data', () => {
260+
it('with standard fields', () => {
240261

241-
service.registerAccount(registerData).subscribe();
262+
service.registerAccount(registerData).subscribe();
242263

243-
const req = backend.expectOne({
244-
url: 'auth',
245-
method: 'POST'
264+
const req = backend.expectOne({
265+
url: 'auth',
266+
method: 'POST'
267+
});
268+
269+
expect(req.request.body).toEqual(registerDataOutput);
270+
});
271+
272+
it('with custom fields', () => {
273+
274+
service.registerAccount(registerCustomFieldsData).subscribe();
275+
276+
const req = backend.expectOne({
277+
url: 'auth',
278+
method: 'POST'
279+
});
280+
281+
expect(req.request.body).toEqual(registerCustomFieldsDataOutput);
246282
});
247283

248-
expect(req.request.body).toEqual(registerDataOutput);
249284
});
250285

251286
it('validateToken should GET', () => {

projects/angular-token/src/lib/angular-token.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export class AngularTokenService implements CanActivate {
135135
// Register request
136136
registerAccount(registerData: RegisterData): Observable<any> {
137137

138+
registerData = Object.assign({}, registerData);
139+
138140
if (registerData.userType == null) {
139141
this.userType = null;
140142
} else {
@@ -146,19 +148,17 @@ export class AngularTokenService implements CanActivate {
146148
registerData.password_confirmation == null &&
147149
registerData.passwordConfirmation != null
148150
) {
149-
registerData.password_confirmation = registerData.passwordConfirmation;
151+
registerData.password_confirmation = registerData.passwordConfirmation;
150152
delete registerData.passwordConfirmation;
151153
}
152154

153-
const body = {
154-
[this.options.loginField]: registerData.login,
155-
password: registerData.password,
156-
password_confirmation: registerData.password_confirmation,
157-
};
155+
const login = registerData.login;
156+
delete registerData.login;
157+
registerData[this.options.loginField] = login;
158158

159159
registerData.confirm_success_url = this.options.registerAccountCallback;
160160

161-
return this.http.post(this.getServerPath() + this.options.registerAccountPath, body);
161+
return this.http.post(this.getServerPath() + this.options.registerAccountPath, registerData);
162162
}
163163

164164
// Delete Account

0 commit comments

Comments
 (0)