From 95cd22e76ff31e43ac446fe51c9d489c8b2717f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 19 Oct 2023 10:45:48 +0200 Subject: [PATCH] MOBILE-4362 workshop: Fix phantom offline submissions --- .../mod/workshop/services/workshop-helper.ts | 38 ++++++++++--------- .../workshop/tests/behat/basic_usage.feature | 3 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/addons/mod/workshop/services/workshop-helper.ts b/src/addons/mod/workshop/services/workshop-helper.ts index c868bfd6e..55eaa30b2 100644 --- a/src/addons/mod/workshop/services/workshop-helper.ts +++ b/src/addons/mod/workshop/services/workshop-helper.ts @@ -449,7 +449,14 @@ export class AddonModWorkshopHelperProvider { * @returns Promise resolved with the files. */ async applyOfflineData( - submission: AddonModWorkshopSubmissionDataWithOfflineData = { + submission?: AddonModWorkshopSubmissionDataWithOfflineData, + actions: AddonModWorkshopOfflineSubmission[] = [], + ): Promise { + if (actions.length === 0) { + return submission; + } + + const baseSubmission = submission ?? { id: 0, workshopid: 0, title: '', @@ -462,12 +469,7 @@ export class AddonModWorkshopHelperProvider { attachment: 0, published: false, late: 0, - }, - actions: AddonModWorkshopOfflineSubmission[] = [], - ): Promise { - if (actions.length === 0) { - return submission; - } + }; let attachmentsId: CoreFileUploaderStoreFilesResult | undefined; const workshopId = actions[0].workshopid; @@ -476,17 +478,17 @@ export class AddonModWorkshopHelperProvider { switch (action.action) { case AddonModWorkshopAction.ADD: case AddonModWorkshopAction.UPDATE: - submission.title = action.title; - submission.content = action.content; - submission.title = action.title; - submission.courseid = action.courseid; - submission.submissionmodified = action.timemodified / 1000; - submission.offline = true; + baseSubmission.title = action.title; + baseSubmission.content = action.content; + baseSubmission.title = action.title; + baseSubmission.courseid = action.courseid; + baseSubmission.submissionmodified = action.timemodified / 1000; + baseSubmission.offline = true; attachmentsId = action.attachmentsid as CoreFileUploaderStoreFilesResult; break; case AddonModWorkshopAction.DELETE: - submission.deleted = true; - submission.submissionmodified = action.timemodified / 1000; + baseSubmission.deleted = true; + baseSubmission.submissionmodified = action.timemodified / 1000; break; default: } @@ -494,13 +496,13 @@ export class AddonModWorkshopHelperProvider { // Check offline files for latest attachmentsid. if (attachmentsId) { - submission.attachmentfiles = + baseSubmission.attachmentfiles = await this.getSubmissionFilesFromOfflineFilesObject(attachmentsId, workshopId); } else { - submission.attachmentfiles = []; + baseSubmission.attachmentfiles = []; } - return submission; + return baseSubmission; } /** diff --git a/src/addons/mod/workshop/tests/behat/basic_usage.feature b/src/addons/mod/workshop/tests/behat/basic_usage.feature index 9d6aee8f5..92d780cc8 100644 --- a/src/addons/mod/workshop/tests/behat/basic_usage.feature +++ b/src/addons/mod/workshop/tests/behat/basic_usage.feature @@ -49,13 +49,14 @@ Feature: Test basic usage of workshop activity in app Given I entered the workshop activity "workshop" on course "Course 1" as "student1" in the app Then I should find "Task to do" within "Submit your work" "ion-item" in the app - When I press "Edit submission" in the app + When I press "Add submission" in the app And I set the field "Title" to "The Answer" in the app And I set the field "Submission content" to "42" in the app And I press "Save" in the app Then I should find "Task done" within "Submit your work" "ion-item" in the app And I should find "The Answer" in the app And I should find "42" in the app + And I should find "Edit submission" in the app Given I entered the workshop activity "workshop" on course "Course 1" as "teacher1" in the app When I pull to refresh in the app