Skip to content

Commit

Permalink
Add check for submission.id before delete call
Browse files Browse the repository at this point in the history
When a submission workflow is canceled.
  • Loading branch information
rpoet-jh committed May 22, 2024
1 parent bf95d29 commit 088e26c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/controllers/submissions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ export default class SubmissionsNew extends Controller {
});

if (result.value) {
await this.submissionHandler.deleteSubmission(submission);
// Clear the shared ignore list, then add the 'deleted' submission ID
ignoreList.clearIgnore();
ignoreList.ignore(get(submission, 'id'));
if (submission.id) {
await this.submissionHandler.deleteSubmission(submission);
ignoreList.ignore(get(submission, 'id'));
}
this.router.transitionTo('submissions');
}
}
Expand Down
50 changes: 49 additions & 1 deletion tests/unit/controllers/submissions/new-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,12 @@ module('Unit | Controller | submissions/new', (hooks) => {
test('abort should delete submission and transition', async function (assert) {
assert.expect(3);

let submission = EmberObject.create({
id: 'sub:0',
});

const model = EmberObject.create({
newSubmission: EmberObject.create(),
newSubmission: submission,
});
const controller = this.owner.lookup('controller:submissions/new');

Expand Down Expand Up @@ -349,4 +353,48 @@ module('Unit | Controller | submissions/new', (hooks) => {

controller.send('abort');
});

test('abort should not delete submission if submission.id is undefined', async function (assert) {
assert.expect(3);

let submission = EmberObject.create({
id: undefined,
});

const model = EmberObject.create({
newSubmission: submission,
});
const controller = this.owner.lookup('controller:submissions/new');

controller.set('model', model);

// Mock global 'swal' for this test
swal = () => {
assert.ok(true);
return Promise.resolve({
value: 'moo',
});
};

let deleteSubmissionCalled = false;

// Having this mocked function run shows that the service will delete the submission
controller.set(
'submissionHandler',
EmberObject.create({
deleteSubmission(_sub) {
deleteSubmissionCalled = true;
return Promise.resolve();
},
})
);
controller.set('router', {
transitionTo: (name) => {
assert.false(deleteSubmissionCalled);
assert.strictEqual(name, 'submissions', 'unexpected transition was named');
},
});

controller.send('abort');
});
});

0 comments on commit 088e26c

Please sign in to comment.