Skip to content

Commit

Permalink
Conserta testes para rotas depois do login
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielaTiago committed Dec 12, 2023
1 parent e9ff457 commit 32d5dab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
27 changes: 11 additions & 16 deletions src/app/pages/login-social/login-social.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,25 @@ declare global {
}
}


@Component({
selector: 'app-login-social',
templateUrl: './login-social.component.html',
styleUrls: ['./login-social.component.css']
styleUrls: ['./login-social.component.css'],
})
export class LoginSocialComponent implements OnInit {
private user: SocialUser | null = null;
private loggedIn: boolean = false;


constructor(
private authService: SocialAuthService,
private http: HttpClient,
private router: Router,
private Service: AuthService
) { }


) {}

ngOnInit(): void {
window['handleCredentialResponse'] = this.handleCredentialResponse.bind(this);
window['handleCredentialResponse'] =
this.handleCredentialResponse.bind(this);
this.loadGoogleButton();
}

Expand All @@ -65,18 +62,16 @@ export class LoginSocialComponent implements OnInit {
const payload = jwt.split('.')[1];
const decodedPayload = atob(payload);
const userInformation = JSON.parse(decodedPayload);

const user: SocialUser = new SocialUser();
user.name = userInformation.name;
user.email = userInformation.email;

this.sendUserDataToServer(user);
}


signInWithFB(): void {
this.authService.signIn(FacebookLoginProvider.PROVIDER_ID).then((user) => {

if (user) {
this.sendUserDataToServer(user);
}
Expand All @@ -90,16 +85,16 @@ export class LoginSocialComponent implements OnInit {
private sendUserDataToServer(user: SocialUser) {
const userSocialData = {
name: user.name,
email: user.email
email: user.email,
};

this.Service.loginSocialUser(userSocialData).subscribe(
(response) => {
console.log('Resposta do servidor:', response);
if (response && response.access_token) {

if (response && response.access_token) {
localStorage.setItem('token', response.access_token);

if (response.is_new_user) {
this.router.navigate([`/editUser/${response.user_id}`]);
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/app/pages/login/login.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { CheckCodeRestPasswordComponent } from '../check-code-rest-password/chec
import { RegisterComponent } from '../register/register.component';
import { of, throwError } from 'rxjs';
import { AlertService } from '../../services/alert.service';
import { VideoComponent } from '../video/video.component';
import { CatalogComponent } from '../catalog/catalog.component';

import { HttpErrorResponse } from '@angular/common/http';
import { ActiveAccountComponent } from '../active-account/active-account.component';

Expand Down Expand Up @@ -60,7 +61,7 @@ describe('LoginComponent', () => {
component: CheckCodeRestPasswordComponent,
},
{ path: 'register', component: RegisterComponent },
{ path: 'videos', component: VideoComponent },
{ path: 'catalog', component: CatalogComponent },
{ path: 'activeAccount', component: ActiveAccountComponent },
]),
],
Expand Down Expand Up @@ -142,7 +143,8 @@ describe('LoginComponent', () => {

it('should call navigator method when "Login com redes sociais" is clicked', () => {
const navigatorSpy = spyOn(component, 'navigator').and.callThrough();
const loginSocial = fixture.nativeElement.querySelector('#loginSocialButton');
const loginSocial =
fixture.nativeElement.querySelector('#loginSocialButton');
loginSocial.click();

expect(navigatorSpy).toHaveBeenCalledWith('/loginsocial');
Expand Down

0 comments on commit 32d5dab

Please sign in to comment.