diff --git a/app/coffeescripts/models/QuizOverrideLoader.coffee b/app/coffeescripts/models/QuizOverrideLoader.coffee index d697a74e2bd..25870ad8754 100644 --- a/app/coffeescripts/models/QuizOverrideLoader.coffee +++ b/app/coffeescripts/models/QuizOverrideLoader.coffee @@ -44,11 +44,15 @@ define [ quiz.set('loadingOverrides', false) _chooseLatest: (dates, type) -> + if _.any(dates, (d) -> _.isNull(d[type]) || _.isUndefined(d[type])) + return null sortedDates = @_sortedDatesOfType(dates, type) if _.any(sortedDates) _.last(sortedDates) _chooseEarliest: (dates, type) -> + if _.any(dates, (d) -> _.isNull(d[type]) || _.isUndefined(d[type])) + return null sortedDates = @_sortedDatesOfType(dates, type) if _.any(sortedDates) _.first(sortedDates) diff --git a/spec/coffeescripts/quizzes/QuizOverrideLoaderSpec.js b/spec/coffeescripts/quizzes/QuizOverrideLoaderSpec.js index 9a6915c8697..f1a146dc80d 100644 --- a/spec/coffeescripts/quizzes/QuizOverrideLoaderSpec.js +++ b/spec/coffeescripts/quizzes/QuizOverrideLoaderSpec.js @@ -41,9 +41,15 @@ test('can select the earliest date from a group', function() { equal(this.loader._chooseEarliest(this.dates, 'unlock_at'), this.earliestDate) }) -test('ignores null dates and handles empty arrays', function() { +test('handles null dates and handles empty arrays', function() { let dates = [{}, {}] equal(this.loader._chooseLatest(dates, 'due_at'), null) dates = [] equal(this.loader._chooseLatest(dates, 'due_at'), null) }) + +test('returns null if any argument is null', function() { + const dates = [...this.dates, {}] + equal(this.loader._chooseLatest(dates, 'due_at'), null) + equal(this.loader._chooseEarliest(dates, 'due_at'), null) +})