Skip to content

Commit cf2ad5c

Browse files
authored
SAK-51588 Conversations sakai-topic test race condition (#13819)
1 parent 1427fdc commit cf2ad5c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

webcomponents/tool/src/main/frontend/packages/sakai-conversations/src/SakaiTopic.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ export class SakaiTopic extends reactionsAndUpvotingMixin(SakaiElement) {
113113

114114
// If there are no new posts to mark as viewed, return early
115115
if (newPostIds.length === 0) {
116-
return;
116+
return Promise.resolve();
117117
}
118118

119119
// Add these posts to our tracked set before making the request
120120
newPostIds.forEach(id => this._observedPosts.add(id));
121121

122122
const url = this.topic.links.find(l => l.rel === "markpostsviewed").href;
123-
fetch(url, {
123+
return fetch(url, {
124124
method: "POST",
125125
headers: { "Content-Type": "application/json" },
126126
body: JSON.stringify(newPostIds),
@@ -149,7 +149,10 @@ export class SakaiTopic extends reactionsAndUpvotingMixin(SakaiElement) {
149149
throw new Error(`Network error while marking posts as viewed at url ${url}`);
150150
}
151151
})
152-
.catch (error => console.error(error));
152+
.catch (error => {
153+
console.error(error);
154+
throw error;
155+
});
153156
}
154157

155158
_savePostAsDraft() { this._postToTopic(true); }

webcomponents/tool/src/main/frontend/packages/sakai-conversations/test/topic.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,13 @@ describe("sakai-topic tests", () => {
566566
const originalObserver = el.observer;
567567
el.observer = { observe: observeSpy, unobserve: unobserveSpy };
568568

569+
// Set up event listener for "posts-viewed" before calling the method
570+
const eventPromise = oneEvent(el, "posts-viewed");
571+
569572
// Call the method directly with the post IDs
570-
el._markPostsViewed(["post1"]);
573+
await el._markPostsViewed(["post1"]);
571574

572-
const { detail } = await oneEvent(el, "posts-viewed");
575+
const { detail } = await eventPromise;
573576

574577
expect(detail.postIds).to.include("post1");
575578
expect(detail.topicId).to.equal(topic.id);

0 commit comments

Comments
 (0)