feat(auth): integrate TenantService to include tenant code in registration payload
This commit is contained in:
@@ -6,6 +6,7 @@ import { HttpTestingController, provideHttpClientTesting } from '@angular/common
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { AuthService } from './auth.service';
|
||||
import { CookieService } from '../cookie/cookie.service';
|
||||
import { TenantService } from '../tenant.service';
|
||||
|
||||
describe('AuthService', () => {
|
||||
let cookieStore: Record<string, string> = {};
|
||||
@@ -132,6 +133,10 @@ describe('AuthService', () => {
|
||||
provideHttpClientTesting(),
|
||||
AuthService,
|
||||
{ provide: CookieService, useValue: createCookieServiceStub() },
|
||||
{
|
||||
provide: TenantService,
|
||||
useValue: { getTenant: () => ({ codigo: 'tenant-test' }) }
|
||||
},
|
||||
TransferState
|
||||
]
|
||||
});
|
||||
@@ -152,6 +157,7 @@ describe('AuthService', () => {
|
||||
|
||||
const request = httpController.expectOne(`${environment.url}register`);
|
||||
expect(request.request.method).toBe('POST');
|
||||
expect(request.request.body.tenant_codigo).toBe('tenant-test');
|
||||
request.flush({
|
||||
message: 'Usuario registrado correctamente.',
|
||||
data: {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
UpdateProfilePayload
|
||||
} from './auth.interfaces';
|
||||
import { CookieService } from '../cookie/cookie.service';
|
||||
import { TenantService } from '../tenant.service';
|
||||
|
||||
const AUTH_TOKEN_COOKIE_KEY = 'shopit.auth.token';
|
||||
const AUTH_USER_SSR_STATE_KEY = makeStateKey<AuthUser>('shopit.auth.user');
|
||||
@@ -25,6 +26,7 @@ export class AuthService {
|
||||
private readonly platformId = inject(PLATFORM_ID);
|
||||
private readonly cookieService = inject(CookieService);
|
||||
private readonly transferState = inject(TransferState);
|
||||
private readonly tenantService = inject(TenantService);
|
||||
|
||||
private readonly userState = signal<AuthUser | null>(null);
|
||||
private readonly tokenState = signal<string | null>(null);
|
||||
@@ -41,7 +43,12 @@ export class AuthService {
|
||||
}
|
||||
|
||||
register(payload: RegisterPayload): Observable<RegisterResponse> {
|
||||
return this.http.post<RegisterResponse>(`${environment.url}register`, payload);
|
||||
const tenantCode = this.tenantService.getTenant()?.codigo;
|
||||
|
||||
return this.http.post<RegisterResponse>(`${environment.url}register`, {
|
||||
...payload,
|
||||
...(tenantCode ? { tenant_codigo: tenantCode } : {})
|
||||
});
|
||||
}
|
||||
|
||||
updateProfile(payload: UpdateProfilePayload): Observable<AuthUser> {
|
||||
|
||||
@@ -50,8 +50,8 @@ describe('RegisterPageComponent', () => {
|
||||
component.form.setValue({
|
||||
nombre_apellido: 'Ada Lovelace',
|
||||
email: 'ada@example.com',
|
||||
password: 'secret123',
|
||||
password_confirmation: 'secret123'
|
||||
password: 'Secret!123',
|
||||
password_confirmation: 'Secret!123'
|
||||
});
|
||||
|
||||
component.onSubmit();
|
||||
@@ -59,8 +59,8 @@ describe('RegisterPageComponent', () => {
|
||||
expect(authService.register).toHaveBeenCalledWith({
|
||||
nombre_apellido: 'Ada Lovelace',
|
||||
email: 'ada@example.com',
|
||||
password: 'secret123',
|
||||
password_confirmation: 'secret123'
|
||||
password: 'Secret!123',
|
||||
password_confirmation: 'Secret!123'
|
||||
});
|
||||
expect(modalService.openSimple).toHaveBeenCalledWith({
|
||||
content: 'Tu cuenta fue creada correctamente',
|
||||
@@ -178,8 +178,8 @@ describe('RegisterPageComponent', () => {
|
||||
component.form.setValue({
|
||||
nombre_apellido: 'Ada Lovelace',
|
||||
email: 'ada@example.com',
|
||||
password: 'secret123',
|
||||
password_confirmation: 'secret123'
|
||||
password: 'Secret!123',
|
||||
password_confirmation: 'Secret!123'
|
||||
});
|
||||
component.onSubmit();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user