Skip to content

Commit

Permalink
General: Fix an error in the detail overview list due to an empty sub…
Browse files Browse the repository at this point in the history
…mission policy (#8028)
  • Loading branch information
bassner authored Feb 13, 2024
1 parent 12fa532 commit db97fd4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Observable, map } from 'rxjs';
import { SubmissionPolicy } from 'app/entities/submission-policy.model';

export interface ISubmissionPolicyService {
addSubmissionPolicyToProgrammingExercise: (submissionPolicy: SubmissionPolicy, exerciseId: number) => Observable<SubmissionPolicy>;
getSubmissionPolicyOfProgrammingExercise: (exerciseId: number) => Observable<SubmissionPolicy>;
getSubmissionPolicyOfProgrammingExercise: (exerciseId: number) => Observable<SubmissionPolicy | undefined>;
removeSubmissionPolicyFromProgrammingExercise: (exerciseId: number) => Observable<HttpResponse<void>>;
enableSubmissionPolicyOfProgrammingExercise: (exerciseId: number) => Observable<HttpResponse<void>>;
disableSubmissionPolicyOfProgrammingExercise: (exerciseId: number) => Observable<HttpResponse<void>>;
Expand All @@ -24,8 +24,14 @@ export class SubmissionPolicyService implements ISubmissionPolicyService {
*
* @param exerciseId of the programming exercise for which the submission policy should be loaded
*/
getSubmissionPolicyOfProgrammingExercise(exerciseId: number): Observable<SubmissionPolicy> {
return this.http.get<SubmissionPolicy>(this.requestUrl(exerciseId));
getSubmissionPolicyOfProgrammingExercise(exerciseId: number): Observable<SubmissionPolicy | undefined> {
return this.http.get<SubmissionPolicy | undefined>(this.requestUrl(exerciseId)).pipe(
// using any as it can be null
map((response: any) => {
// Ensure that null is replaced by undefined
return response === null ? undefined : response;
}),
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class CourseExerciseDetailsComponent extends AbstractScienceComponent imp
private discussionComponent?: DiscussionSectionComponent;
baseResource: string;
isExamExercise: boolean;
submissionPolicy: SubmissionPolicy;
submissionPolicy?: SubmissionPolicy;
exampleSolutionCollapsed: boolean;
plagiarismCaseInfo?: PlagiarismCaseInfo;
availableExerciseHints: ExerciseHint[];
Expand Down
35 changes: 20 additions & 15 deletions src/test/javascript/spec/service/submission-policy.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,26 @@ describe('Submission Policy Service', () => {
addPolicySubscription.unsubscribe();
}));

it('should get submission policy from exercise', fakeAsync(() => {
const getPolicySubscription = submissionPolicyService
.getSubmissionPolicyOfProgrammingExercise(programmingExercise.id!)
.pipe(take(1))
.subscribe((submissionPolicy) => {
expect(submissionPolicy).toBe(lockRepositoryPolicy);
});
tick();

const request = httpMock.expectOne({ method: 'GET', url: expectedUrl });
request.flush(lockRepositoryPolicy);
tick();

getPolicySubscription.unsubscribe();
}));
// Using functions to avoid a serialization error
it.each([() => ({ input: null, expected: undefined }), () => ({ input: lockRepositoryPolicy, expected: lockRepositoryPolicy })])(
'should get submission policy from exercise',
fakeAsync((fun: any) => {
const { input, expected } = fun();
const getPolicySubscription = submissionPolicyService
.getSubmissionPolicyOfProgrammingExercise(programmingExercise.id!)
.pipe(take(1))
.subscribe((submissionPolicy) => {
expect(submissionPolicy).toBe(expected);
});
tick();

const request = httpMock.expectOne({ method: 'GET', url: expectedUrl });
request.flush(input);
tick();

getPolicySubscription.unsubscribe();
}),
);

it('should issue delete request', fakeAsync(() => {
const removePolicySubscription = submissionPolicyService.removeSubmissionPolicyFromProgrammingExercise(programmingExercise.id!).subscribe((response) => {
Expand Down

0 comments on commit db97fd4

Please sign in to comment.