Fixes failing tests by separating xhr requests to api services

parent 419ed758
Pipeline #16307 passed with stages
in 5 minutes and 30 seconds
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
......@@ -56,11 +56,10 @@ describe('AdditionalDataComponent', () => {
expect(AdditionalDataComponent.TYPE).toEqual('AdditionalDataComponent');
}));
it('#switchShowMoreOrLess', (inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
const baseState = window.innerWidth >= 768;
expect(component.isShowingMore).toEqual(baseState);
component.switchShowMoreOrLess();
expect(component.isShowingMore).toEqual(!baseState);
})));
it('#switchShowMoreOrLess', () => {
const baseState = window.innerWidth >= 768;
expect(component.isShowingMore).toEqual(baseState);
component.switchShowMoreOrLess();
expect(component.isShowingMore).toEqual(!baseState);
});
});
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
......@@ -78,13 +78,13 @@ describe('FooterBarComponent', () => {
expect(FooterBarComponent.TYPE).toEqual('FooterBarComponent');
}));
it('#getLinkTarget', (inject([HttpClient, HttpTestingController, FooterBarService],
(http: HttpClient, backend: HttpTestingController, footerBarService: FooterBarService) => {
it('#getLinkTarget', (inject([FooterBarService],
(footerBarService: FooterBarService) => {
expect(component.getLinkTarget(footerBarService.footerElemAbout)).toEqual(jasmine.arrayContaining(['info', 'about']));
})));
it('#toggleSetting', (inject([HttpClient, HttpTestingController, FooterBarService, TrackingService],
(http: HttpClient, backend: HttpTestingController, footerBarService: FooterBarService, trackingService: TrackingService) => {
it('#toggleSetting', (inject([FooterBarService, TrackingService],
(footerBarService: FooterBarService, trackingService: TrackingService) => {
const elem = footerBarService.footerElemAbout;
spyOn(elem, 'onClickCallback').and.callFake(() => {});
spyOn(trackingService, 'trackClickEvent').and.callFake(() => {});
......@@ -93,15 +93,15 @@ describe('FooterBarComponent', () => {
expect(trackingService.trackClickEvent).toHaveBeenCalled();
})));
it('#fileChange', (inject([HttpClient, HttpTestingController, FileUploadService],
(http: HttpClient, backend: HttpTestingController, fileUploadService: FileUploadService) => {
it('#fileChange', (inject([FileUploadService],
(fileUploadService: FileUploadService) => {
spyOn(fileUploadService, 'uploadFile').and.callFake(() => {});
component.fileChange({ target: { files: [{ name: 'testFile' }] } });
expect(fileUploadService.uploadFile).toHaveBeenCalled();
})));
it('#moveLeft', (inject([HttpClient, HttpTestingController, FooterBarService],
(http: HttpClient, backend: HttpTestingController, footerBarService: FooterBarService) => {
it('#moveLeft', (inject([FooterBarService],
(footerBarService: FooterBarService) => {
component.footerElements = [
...Object.keys(footerBarService).map(t => footerBarService[t] instanceof FooterbarElement ? footerBarService[t] : false),
];
......@@ -112,8 +112,8 @@ describe('FooterBarComponent', () => {
expect(component.footerElemIndex).toEqual(1);
})));
it('#moveRight', (inject([HttpClient, HttpTestingController, FooterBarService],
(http: HttpClient, backend: HttpTestingController, footerBarService: FooterBarService) => {
it('#moveRight', (inject([FooterBarService],
(footerBarService: FooterBarService) => {
component.footerElements = [
...Object.keys(footerBarService).map(t => footerBarService[t] instanceof FooterbarElement ? footerBarService[t] : false),
];
......
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
import { DefaultSettings } from '../../../lib/default.settings';
import { createTranslateLoader } from '../../../lib/translation.factory';
import { ActiveQuestionGroupMockService } from '../../service/active-question-group/active-question-group.mock.service';
import { ActiveQuestionGroupService } from '../../service/active-question-group/active-question-group.service';
import { LobbyApiService } from '../../service/api/lobby/lobby-api.service';
import { QuizApiService } from '../../service/api/quiz/quiz-api.service';
import { ConnectionMockService } from '../../service/connection/connection.mock.service';
import { ConnectionService } from '../../service/connection/connection.service';
import { CurrentQuizMockService } from '../../service/current-quiz/current-quiz.mock.service';
import { CurrentQuizService } from '../../service/current-quiz/current-quiz.service';
import { FileUploadMockService } from '../../service/file-upload/file-upload.mock.service';
import { FileUploadService } from '../../service/file-upload/file-upload.service';
import { FooterBarService } from '../../service/footer-bar/footer-bar.service';
import { SettingsService } from '../../service/settings/settings.service';
import { SharedService } from '../../service/shared/shared.service';
......@@ -27,7 +30,6 @@ import { AvailableQuizzesComponent } from './available-quizzes.component';
describe('AvailableQuizzesComponent', () => {
let component: AvailableQuizzesComponent;
let fixture: ComponentFixture<AvailableQuizzesComponent>;
let backend: HttpTestingController;
beforeEach(async(() => {
TestBed.configureTestingModule({
......@@ -50,6 +52,8 @@ describe('AvailableQuizzesComponent', () => {
],
providers: [
NgbActiveModal,
LobbyApiService,
QuizApiService,
{ provide: TrackingService, useClass: TrackingMockService },
{ provide: CurrentQuizService, useClass: CurrentQuizMockService },
FooterBarService,
......@@ -58,6 +62,7 @@ describe('AvailableQuizzesComponent', () => {
{ provide: WebsocketService, useClass: WebsocketMockService },
SharedService,
{ provide: ActiveQuestionGroupService, useClass: ActiveQuestionGroupMockService },
{ provide: FileUploadService, useClass: FileUploadMockService },
],
declarations: [AvailableQuizzesComponent],
}).compileComponents();
......@@ -67,14 +72,8 @@ describe('AvailableQuizzesComponent', () => {
fixture = TestBed.createComponent(AvailableQuizzesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
backend = TestBed.get(HttpTestingController);
}));
afterEach(() => {
backend.verify();
});
it('should be created', async(() => {
expect(component).toBeTruthy();
}));
......@@ -115,28 +114,20 @@ describe('AvailableQuizzesComponent', () => {
it('#startQuiz', (inject(
[CurrentQuizService, TrackingService],
async (currentQuizService: CurrentQuizService, trackingService: TrackingService) => {
(currentQuizService: CurrentQuizService, trackingService: TrackingService,
) => {
const quiz = currentQuizService.quiz;
spyOn(trackingService, 'trackClickEvent').and.callFake(() => {});
component.startQuiz(quiz);
const req1 = backend.expectOne({
url: `${DefaultSettings.httpApiEndpoint}/quiz/status/${quiz.hashtag}`,
method: 'GET',
});
req1.flush({
'status': 'STATUS:SUCCESSFUL',
'step': 'QUIZ:UNDEFINED',
});
expect(trackingService.trackClickEvent).toHaveBeenCalled();
})));
it('#editQuiz', (inject(
[CurrentQuizService, TrackingService, ActiveQuestionGroupService, Router],
async (
(
currentQuizService: CurrentQuizService,
trackingService: TrackingService,
activeQuestionGroupService: ActiveQuestionGroupService,
......
import { HttpClient } from '@angular/common/http';
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { Component, Inject, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { IMessage } from 'arsnova-click-v2-types/src/common';
import { IModal } from 'arsnova-click-v2-types/src/modals/interfaces';
import { IQuestionGroup } from 'arsnova-click-v2-types/src/questions/interfaces';
import { questionGroupReflection } from 'arsnova-click-v2-types/src/questions/questionGroup_reflection';
import { DefaultSettings } from '../../../lib/default.settings';
import { ActiveQuestionGroupService } from '../../service/active-question-group/active-question-group.service';
import { LobbyApiService } from '../../service/api/lobby/lobby-api.service';
import { QuizApiService } from '../../service/api/quiz/quiz-api.service';
import { CurrentQuizService } from '../../service/current-quiz/current-quiz.service';
import { FileUploadService } from '../../service/file-upload/file-upload.service';
import { TrackingService } from '../../service/tracking/tracking.service';
......@@ -17,7 +16,7 @@ import { TrackingService } from '../../service/tracking/tracking.service';
templateUrl: './available-quizzes.component.html',
styleUrls: ['./available-quizzes.component.scss'],
})
export class AvailableQuizzesComponent implements OnInit, IModal {
export class AvailableQuizzesComponent implements IModal {
public static TYPE = 'AvailableQuizzesComponent';
private _sessions: Array<IQuestionGroup> = [];
......@@ -29,12 +28,13 @@ export class AvailableQuizzesComponent implements OnInit, IModal {
constructor(
@Inject(PLATFORM_ID) private platformId: Object,
private activeModal: NgbActiveModal,
private http: HttpClient,
private router: Router,
private currentQuizService: CurrentQuizService,
private activeQuestionGroupService: ActiveQuestionGroupService,
private trackingService: TrackingService,
private fileUploadService: FileUploadService,
private quizApiService: QuizApiService,
private lobbyApiService: LobbyApiService,
) {
const sessions = JSON.parse(window.localStorage.getItem('config.owned_quizzes')) || [];
sessions.sort((a, b) => a > b);
......@@ -61,16 +61,17 @@ export class AvailableQuizzesComponent implements OnInit, IModal {
return new Promise(async resolve => {
this.trackingService.trackClickEvent({ action: AvailableQuizzesComponent.TYPE, label: 'start-quiz' });
const quizStatusData = await this.http.get<IMessage>(`${DefaultSettings.httpApiEndpoint}/quiz/status/${session.hashtag}`).toPromise();
const quizStatusData = await this.quizApiService.getQuizStatus(session.hashtag).toPromise();
if (quizStatusData.status !== 'STATUS:SUCCESSFUL') {
resolve();
return;
}
if (quizStatusData.step === 'QUIZ:UNDEFINED') {
await this.http.post<IMessage>(`${DefaultSettings.httpApiEndpoint}/quiz/reserve/override`, {
const quizReservationOverrideResult = await this.quizApiService.postQuizReservationOverride({
quizName: session.hashtag,
privateKey: window.localStorage.getItem('config.private_key'),
}).toPromise();
} else if (quizStatusData.step === 'QUIZ:AVAILABLE') {
const blob = new Blob([JSON.stringify(session.serialize())], { type: 'application/json' });
......@@ -92,7 +93,7 @@ export class AvailableQuizzesComponent implements OnInit, IModal {
this.currentQuizService.quiz = session;
await this.currentQuizService.cacheQuiz();
const openQuizRequestData = await this.http.put<IMessage>(`${DefaultSettings.httpApiEndpoint}/lobby`, {
const openQuizRequestData = await this.lobbyApiService.putLobby({
quiz: this.currentQuizService.quiz.serialize(),
}).toPromise();
......@@ -114,7 +115,4 @@ export class AvailableQuizzesComponent implements OnInit, IModal {
this.next();
}
public ngOnInit(): void {
}
}
......@@ -4,6 +4,7 @@ import { RouterTestingModule } from '@angular/router/testing';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
import { createTranslateLoader } from '../../../../lib/translation.factory';
import { MemberApiService } from '../../../service/api/member/member-api.service';
import { AttendeeMockService } from '../../../service/attendee/attendee.mock.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionMockService } from '../../../service/connection/connection.mock.service';
......@@ -48,6 +49,7 @@ describe('QuizFlow: ConfidenceRateComponent', () => {
{ provide: WebsocketService, useClass: WebsocketMockService },
SharedService,
SettingsService,
MemberApiService,
],
declarations: [ConfidenceRateComponent],
}).compileComponents();
......@@ -80,4 +82,13 @@ describe('QuizFlow: ConfidenceRateComponent', () => {
expect(component.getConfidenceLevel()).toEqual('no_idea');
}));
it('#sendConfidence', async(() => {
spyOn(component, 'sendConfidence').and.callFake(() => {});
component.sendConfidence();
expect(component.sendConfidence).not.toThrowError();
}),
);
});
import { HttpClient } from '@angular/common/http';
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
import { IMessage } from 'arsnova-click-v2-types/src/common';
import { DefaultSettings } from '../../../../lib/default.settings';
import { Subscription } from 'rxjs/index';
import { MemberApiService } from '../../../service/api/member/member-api.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionService } from '../../../service/connection/connection.service';
import { CurrentQuizService } from '../../../service/current-quiz/current-quiz.service';
......@@ -28,10 +28,10 @@ export class ConfidenceRateComponent implements OnInit {
@Inject(PLATFORM_ID) private platformId: Object,
private connectionService: ConnectionService,
private attendeeService: AttendeeService,
private http: HttpClient,
private router: Router,
private headerLabelService: HeaderLabelService,
private footerBarService: FooterBarService,
private memberApiService: MemberApiService,
) {
headerLabelService.headerLabel = 'component.liveResults.confidence_grade';
......@@ -63,8 +63,8 @@ export class ConfidenceRateComponent implements OnInit {
this._confidenceValue = parseInt((<HTMLInputElement>event.target).value, 10);
}
public sendConfidence(): void {
this.http.put(`${DefaultSettings.httpApiEndpoint}/member/confidence-value`, {
public sendConfidence(): Subscription {
return this.memberApiService.putConfidenceValue({
quizName: this.currentQuizService.quiz.hashtag,
nickname: window.sessionStorage.getItem(`config.nick`),
confidenceValue: this._confidenceValue,
......
import { HttpClient } from '@angular/common/http';
import { Component, OnInit, SecurityContext } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { ActivatedRoute, Router } from '@angular/router';
import { ILeaderBoardItem, IMessage } from 'arsnova-click-v2-types/src/common';
import { Subscription } from 'rxjs';
import { DefaultSettings } from '../../../../lib/default.settings';
import { parseGithubFlavoredMarkdown } from '../../../../lib/markdown/markdown';
import { LeaderboardApiService } from '../../../service/api/leaderboard/leaderboard-api.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionService } from '../../../service/connection/connection.service';
import { CurrentQuizService } from '../../../service/current-quiz/current-quiz.service';
......@@ -65,12 +64,12 @@ export class LeaderboardComponent implements OnInit {
private footerBarService: FooterBarService,
private route: ActivatedRoute,
private headerLabelService: HeaderLabelService,
private http: HttpClient,
private router: Router,
private connectionService: ConnectionService,
public currentQuizService: CurrentQuizService,
public attendeeService: AttendeeService,
private i18nService: I18nService,
private leaderboardApiService: LeaderboardApiService,
) {
this.footerBarService.TYPE_REFERENCE = LeaderboardComponent.TYPE;
......@@ -170,8 +169,7 @@ export class LeaderboardComponent implements OnInit {
}
private async getLeaderboardFromBackend(): Promise<IMessage> {
const url = `${DefaultSettings.httpApiEndpoint}/quiz/leaderboard/${this._hashtag}/${this._questionIndex ? this._questionIndex : ''}`;
return this.http.get<IMessage>(url).toPromise();
return this.leaderboardApiService.getLeaderboardData(this._hashtag, this.questionIndex).toPromise();
}
private handleMessages(): void {
......
......@@ -10,6 +10,8 @@ import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-comp
import { createTranslateLoader } from '../../../../lib/translation.factory';
import { ActiveQuestionGroupMockService } from '../../../service/active-question-group/active-question-group.mock.service';
import { ActiveQuestionGroupService } from '../../../service/active-question-group/active-question-group.service';
import { MemberApiService } from '../../../service/api/member/member-api.service';
import { QuizApiService } from '../../../service/api/quiz/quiz-api.service';
import { AttendeeMockService } from '../../../service/attendee/attendee.mock.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionMockService } from '../../../service/connection/connection.mock.service';
......@@ -21,6 +23,7 @@ import { HeaderLabelService } from '../../../service/header-label/header-label.s
import { I18nService } from '../../../service/i18n/i18n.service';
import { SettingsService } from '../../../service/settings/settings.service';
import { SharedService } from '../../../service/shared/shared.service';
import { ThemesMockService } from '../../../service/themes/themes.mock.service';
import { ThemesService } from '../../../service/themes/themes.service';
import { TrackingMockService } from '../../../service/tracking/tracking.mock.service';
import { TrackingService } from '../../../service/tracking/tracking.service';
......@@ -68,7 +71,9 @@ describe('QuizLobbyComponent', () => {
I18nService,
HeaderLabelService,
{ provide: AttendeeService, useClass: AttendeeMockService },
ThemesService,
{ provide: ThemesService, useClass: ThemesMockService },
MemberApiService,
QuizApiService,
],
declarations: [QuizLobbyComponent],
}).compileComponents();
......
import { isPlatformBrowser } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, Inject, OnDestroy, PLATFORM_ID, SecurityContext } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { IMessage, INickname } from 'arsnova-click-v2-types/src/common';
import { questionGroupReflection } from 'arsnova-click-v2-types/src/questions/questionGroup_reflection';
import { DefaultSettings } from '../../../../lib/default.settings';
import { parseGithubFlavoredMarkdown } from '../../../../lib/markdown/markdown';
import { ActiveQuestionGroupService } from '../../../service/active-question-group/active-question-group.service';
import { MemberApiService } from '../../../service/api/member/member-api.service';
import { QuizApiService } from '../../../service/api/quiz/quiz-api.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionService } from '../../../service/connection/connection.service';
import { CurrentQuizService } from '../../../service/current-quiz/current-quiz.service';
......@@ -56,12 +56,13 @@ export class QuizLobbyComponent implements OnDestroy {
private headerLabelService: HeaderLabelService,
private themesService: ThemesService,
private router: Router,
private http: HttpClient,
private connectionService: ConnectionService,
private sanitizer: DomSanitizer,
private activeQuestionGroupService: ActiveQuestionGroupService,
private modalService: NgbModal,
private trackingService: TrackingService,
private memberApiService: MemberApiService,
private quizApiService: QuizApiService,
) {
this.headerLabelService.headerLabel = this.currentQuizService.quiz.hashtag;
......@@ -90,7 +91,7 @@ export class QuizLobbyComponent implements OnDestroy {
public async kickMember(name: string): Promise<void> {
this._kickMemberModalRef.close();
const quizName = this.currentQuizService.quiz.hashtag;
const data = await this.http.delete<IMessage>(`${DefaultSettings.httpApiEndpoint}/member/${quizName}/${name}`).toPromise();
const data = await this.memberApiService.deleteMember(quizName, name).toPromise();
if (data.status !== 'STATUS:SUCCESSFUL') {
console.log(data);
}
......@@ -156,7 +157,7 @@ export class QuizLobbyComponent implements OnDestroy {
}
const target = this.currentQuizService.quiz.sessionConfig.readingConfirmationEnabled ?
'reading-confirmation' : 'start';
this.http.post(`${DefaultSettings.httpApiEndpoint}/quiz/${target}`, {
this.quizApiService.postQuizData(target, {
quizName: this.currentQuizService.quiz.hashtag,
}).subscribe((data: IMessage) => {
this.currentQuizService.readingConfirmationRequested = data.step === 'QUIZ:READING_CONFIRMATION_REQUESTED';
......
......@@ -94,10 +94,10 @@ describe('ProgressBarComponent', () => {
it('#attendeeDataForAnswer', async(inject(
[CurrentQuizService, AttendeeService, QuestionTextService],
async (currentQuizService: CurrentQuizService, attendeeService: AttendeeService, questionTextService: QuestionTextService) => {
(currentQuizService: CurrentQuizService, attendeeService: AttendeeService, questionTextService: QuestionTextService) => {
component.questionIndex = 0;
const question = <IQuestionChoice>currentQuizService.quiz.questionList[component.questionIndex];
await questionTextService.changeMultiple(question.answerOptionList.map(answer => answer.answerText));
questionTextService.changeMultiple(question.answerOptionList.map(answer => answer.answerText));
questionTextService.eventEmitter.subscribe((value) => {
if (value instanceof Array) {
component.data = value;
......
import { HttpClient } from '@angular/common/http';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { IMessage, INickname } from 'arsnova-click-v2-types/src/common';
......@@ -7,7 +6,7 @@ import { FreeTextQuestion } from 'arsnova-click-v2-types/src/questions/question_
import { RangedQuestion } from 'arsnova-click-v2-types/src/questions/question_ranged';
import { SurveyQuestion } from 'arsnova-click-v2-types/src/questions/question_survey';
import { Countdown } from '../../../../lib/countdown/countdown';
import { DefaultSettings } from '../../../../lib/default.settings';
import { QuizApiService } from '../../../service/api/quiz/quiz-api.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
import { ConnectionService } from '../../../service/connection/connection.service';
import { CurrentQuizService } from '../../../service/current-quiz/current-quiz.service';
......@@ -36,12 +35,12 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
public currentQuizService: CurrentQuizService,
public attendeeService: AttendeeService,
private i18nService: I18nService,
private http: HttpClient,
private router: Router,
private headerLabelService: HeaderLabelService,
private connectionService: ConnectionService,
private footerBarService: FooterBarService,
private questionTextService: QuestionTextService,
private quizApiService: QuizApiService,
) {
this.footerBarService.TYPE_REFERENCE = QuizResultsComponent.TYPE;
......@@ -191,8 +190,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
}
this.handleMessages();
const url = `${DefaultSettings.httpApiEndpoint}/quiz/currentState/${this.currentQuizService.quiz.hashtag}`;
const currentStateData = await this.http.get<IMessage>(url).toPromise();
const currentStateData = await this.quizApiService.getCurrentQuizState(this.currentQuizService.quiz.hashtag).toPromise();
if (currentStateData.status === 'STATUS:SUCCESSFUL') {
const question = this.currentQuizService.currentQuestion();
......@@ -235,8 +233,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
];
}
this.footerBarService.footerElemBack.onClickCallback = async () => {
await this.http.patch<IMessage>(`${DefaultSettings.httpApiEndpoint}/quiz/reset/${this.currentQuizService.quiz.hashtag}`,
{}).toPromise();
await this.quizApiService.patchQuizReset(this.currentQuizService.quiz.hashtag).toPromise();
this.currentQuizService.questionIndex = 0;
this.router.navigate(['/quiz', 'flow', 'lobby']);
};
......@@ -323,7 +320,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
!this.currentQuizService.readingConfirmationRequested ?
'reading-confirmation' : 'start';
const startQuizData = await this.http.post<IMessage>(`${DefaultSettings.httpApiEndpoint}/quiz/${target}`, {
const startQuizData = await this.quizApiService.postQuizData(target, {
quizName: this.currentQuizService.quiz.hashtag,
}).toPromise();
if (startQuizData.status !== 'STATUS:SUCCESSFUL') {
......@@ -354,7 +351,7 @@ export class QuizResultsComponent implements OnInit, OnDestroy {
}
private async stopQuiz(): Promise<void> {
const data = await this.http.post<IMessage>(`${DefaultSettings.httpApiEndpoint}/quiz/stop`, {
const data = await this.quizApiService.postQuizStop({
quizName: this.currentQuizService.quiz.hashtag,
}).toPromise();
if (data.status !== 'STATUS:SUCCESSFUL') {
......
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
......@@ -25,7 +25,6 @@ import { QuizThemeComponent } from './quiz-theme.component';
describe('QuizThemeComponent', () => {
let component: QuizThemeComponent;
let fixture: ComponentFixture<QuizThemeComponent>;
let backend: HttpTestingController;
beforeEach(async(() => {
TestBed.configureTestingModule({
......@@ -61,15 +60,10 @@ describe('QuizThemeComponent', () => {
beforeEach(async(() => {
fixture = TestBed.createComponent(QuizThemeComponent);
backend = TestBed.get(HttpTestingController);
component = fixture.componentInstance;
fixture.detectChanges();
}));
afterEach(() => {
backend.verify();
});
it('should be created', async(() => {
expect(component).toBeTruthy();
}));
......@@ -83,10 +77,9 @@ describe('QuizThemeComponent', () => {
spyOn(currentQuizService, 'toggleSettingByName').and.callThrough();
component.updateTheme(theme).subscribe(() => {
expect(currentQuizService.quiz.sessionConfig.theme).toEqual(theme);
expect(currentQuizService.toggleSettingByName).toHaveBeenCalled();
});
component.updateTheme(theme);
expect(currentQuizService.quiz.sessionConfig.theme).toEqual(theme);
expect(currentQuizService.toggleSettingByName).toHaveBeenCalled();
}),
));
......
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
import { Component, Inject, OnDestroy, PLATFORM_ID } from '@angular/core';
import { Observable } from 'rxjs/index';
import { CurrentQuizService } from '../../../service/current-quiz/current-quiz.service';
import { FooterBarService } from '../../../service/footer-bar/footer-bar.service';
import { ThemesService } from '../../../service/themes/themes.service';
......@@ -36,7 +35,7 @@ export class QuizThemeComponent implements OnDestroy {
this.themesService.updateCurrentlyUsedTheme();
}
public updateTheme(id: string): Observable<void> {
public updateTheme(id: string): void {
if (isPlatformServer(this.platformId)) {
return;
}
......@@ -45,7 +44,7 @@ export class QuizThemeComponent implements OnDestroy {
this.previewThemeBackup = document.getElementsByTagName('html').item(0).dataset['theme'];
this.currentQuizService.quiz.sessionConfig.theme = id;
return this.currentQuizService.toggleSettingByName('theme', id);
this.currentQuizService.toggleSettingByName('theme', id);
}
public previewTheme(id): void {
......
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { async, ComponentFixture, inject, TestBed } from '@angular/core/testing';
import { DomSanitizer } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateCompiler, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler';
import { DefaultSettings } from '../../../../lib/default.settings';
import { createTranslateLoader } from '../../../../lib/translation.factory';
import { AttendeeMockService } from '../../../service/attendee/attendee.mock.service';
import { AttendeeService } from '../../../service/attendee/attendee.service';
......@@ -24,14 +22,12 @@ import { ReadingConfirmationComponent } from './reading-confirmation.component';
describe('QuizFow: ReadingConfirmationComponent', () => {
let component: ReadingConfirmationComponent;
let fixture: ComponentFixture<ReadingConfirmationComponent>;
let backend: HttpTestingController;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
HttpClientModule,
HttpClientTestingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
......@@ -59,15 +55,10 @@ describe('QuizFow: ReadingConfirmationComponent', () => {
beforeEach(async(() => {
fixture = TestBed.createComponent(ReadingConfirmationComponent);
backend = TestBed.get(HttpTestingController);
component = fixture.componentInstance;
fixture.detectChanges();
}));
afterEach(() => {
backend.verify();
});
it('should create', async(() => {
expect(component).toBeTruthy();
}));
......@@ -87,14 +78,9 @@ describe('QuizFow: ReadingConfirmationComponent', () => {
[Router],
(router: Router) => {
const readingConfirmationUrl = `${DefaultSettings.httpApiEndpoint}/member/reading-confirmation`;
const readingConfirmationResponse = {};
spyOn(router, 'navigate').and.callFake(() => {});
spyOn(component, 'confirmReading').and.callFake(() => {});
component.confirmReading().subscribe(() => {
backend.expectOne(readingConfirmationUrl).flush(readingConfirmationResponse);
expect(router.navigate).toHaveBeenCalled();