Skip to content

Commit

Permalink
Development: Use posts for plagiarism cases (#7531)
Browse files Browse the repository at this point in the history
  • Loading branch information
lennart-keller authored Nov 7, 2023
1 parent 8398aa3 commit 37872e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/webapp/app/shared/metis/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,20 @@ export class PostService extends PostingService<Post> {
return res;
}

/**
* Determines whether to use the /messages or /posts API endpoints based on the presence of certain properties in the postContextFilter or post objects.
* If any properties related to conversations are present (conversation, conversationId, or courseWideChannelIds), it returns /messages.
* Otherwise, it defaults to /posts.
*
* @param postContextFilter current post context filter in use
* @param post new or updated post
* @return '/messages' or '/posts'
*/
private static getResourceEndpoint(postContextFilter?: PostContextFilter, post?: Post): string {
if (post?.conversation || postContextFilter?.conversationId) {
if (post?.conversation || postContextFilter?.conversationId || postContextFilter?.courseWideChannelIds) {
return '/messages';
} else {
return '/messages';
return '/posts';
}
}
}
30 changes: 30 additions & 0 deletions src/test/javascript/spec/service/metis/post.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,36 @@ describe('Post Service', () => {
req.flush(returnedFromService);
tick();
}));

it('should use /posts endpoints if plagiarismCaseId is provided in the postContextFilter', fakeAsync(() => {
const plagiarismCaseId = 123;
const expectedUrl = `${service.resourceUrl}${metisCourse.id}/posts?plagiarismCaseId=${plagiarismCaseId}`;
const mockResponse: Post[] = [];

service
.getPosts(metisCourse.id!, { plagiarismCaseId })
.pipe(take(1))
.subscribe((resp) => expect(resp.body).toEqual(mockResponse));
const req = httpMock.expectOne({ method: 'GET', url: expectedUrl });

req.flush(mockResponse);
tick();
}));

it('should use /messages endpoints if course-wide channel ids are provided', fakeAsync(() => {
const courseWideChannelIds = [123];
const expectedUrl = `${service.resourceUrl}${metisCourse.id}/messages?courseWideChannelIds=${courseWideChannelIds}`;
const mockResponse: Post[] = [];

service
.getPosts(metisCourse.id!, { courseWideChannelIds })
.pipe(take(1))
.subscribe((resp) => expect(resp.body).toEqual(mockResponse));
const req = httpMock.expectOne({ method: 'GET', url: expectedUrl });

req.flush(mockResponse);
tick();
}));
});

afterEach(() => {
Expand Down

0 comments on commit 37872e4

Please sign in to comment.