Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ufal/fe-shibboleth-validate-emails #407

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of as observableOf} from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
import {createSuccessfulRemoteDataObject$} from '../../shared/remote-data.utils';
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
import { HELP_DESK_PROPERTY } from '../../item-page/tombstone/tombstone.component';
import { TranslateModule } from '@ngx-translate/core';
import { AuthFailedPageComponent } from './auth-failed-page.component';
import { RequestService } from '../../core/data/request.service';
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { NotificationsService } from '../../shared/notifications/notifications.service';

describe('DuplicateUserErrorComponent', () => {
let component: AuthFailedPageComponent;
let fixture: ComponentFixture<AuthFailedPageComponent>;
let mockConfigurationDataService: ConfigurationDataService;
let requestService: RequestService;
let activatedRoute: any;
let halService: HALEndpointService;
let rdbService: RemoteDataBuildService;
let notificationService: NotificationsServiceStub;

const rootUrl = 'root url';
const queryParams = 'netid[idp]';
const encodedQueryParams = 'netid%5Bidp%5D&email=';

activatedRoute = {
params: observableOf({}),
snapshot: {
queryParams: {
netid: queryParams
}
}
};

mockConfigurationDataService = jasmine.createSpyObj('configurationDataService', {
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
name: HELP_DESK_PROPERTY,
values: [
'email'
]
}))
});

requestService = jasmine.createSpyObj('requestService', {
send: observableOf('response'),
generateRequestId: observableOf('123456'),
});

halService = jasmine.createSpyObj('authService', {
getRootHref: rootUrl,
});

rdbService = getMockRemoteDataBuildService();
notificationService = new NotificationsServiceStub();

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot()
],
declarations: [ AuthFailedPageComponent ],
providers: [
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: ConfigurationDataService, useValue: mockConfigurationDataService },
{ provide: RequestService, useValue: requestService },
{ provide: HALEndpointService, useValue: halService },
{ provide: RemoteDataBuildService, useValue: rdbService },
{ provide: NotificationsService, useValue: notificationService },
]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(AuthFailedPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should send request with encoded netId and email param', () => {
component.ngOnInit();
component.sendEmail();
expect(requestService.send).toHaveBeenCalledWith(jasmine.objectContaining({
href: rootUrl + '/autoregistration?netid=' + encodedQueryParams,
}));
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { RemoteData } from '../../core/data/remote-data';
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
Expand Down Expand Up @@ -42,7 +42,6 @@ export class AuthFailedPageComponent implements OnInit {

constructor(
protected configurationDataService: ConfigurationDataService,
protected router: Router,
public route: ActivatedRoute,
private requestService: RequestService,
protected halService: HALEndpointService,
Expand All @@ -61,7 +60,8 @@ export class AuthFailedPageComponent implements OnInit {
public sendEmail() {
const requestId = this.requestService.generateRequestId();

const url = this.halService.getRootHref() + '/autoregistration?netid=' + this.netid + '&email=' + this.email;
const url = this.halService.getRootHref() + '/autoregistration?netid=' + encodeURIComponent(this.netid) +
'&email=' + encodeURIComponent(this.email);
const postRequest = new PostRequest(requestId, url);
// Send POST request
this.requestService.send(postRequest);
Expand Down
Loading