Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Filter out missing children instead of failing
Browse files Browse the repository at this point in the history
If there's bad data coming in from the server, we might end up in a case
where we get asked for a child that doesn't exist. Instead of giving up
in that case, we should just filter it out.

JIRA: https://openedx.atlassian.net/browse/MA-1972
  • Loading branch information
Akiva Leffert committed Jan 25, 2016
1 parent 45d43b9 commit b4d9e5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Source/CourseOutline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ public struct CourseOutline {
public enum CourseBlockType {
case Unknown(String)
case Course
case Chapter
case Section
case Unit
case Chapter // child of course
case Section // child of chapter
case Unit // child of section
case Video(OEXVideoSummary)
case Problem
case HTML
Expand Down
4 changes: 2 additions & 2 deletions Source/CourseOutlineQuerier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ public class CourseOutlineQuerier : NSObject {
}

private func childrenOfBlockWithID(blockID : CourseBlockID?, forMode mode : CourseOutlineMode, inOutline outline : CourseOutline) -> BlockGroup? {
if let block = self.blockWithID(blockID ?? outline.root, inOutline: outline),
blocks = block.children.mapOrFailIfNil({ self.blockWithID($0, inOutline: outline) })
if let block = self.blockWithID(blockID ?? outline.root, inOutline: outline)
{
let blocks = block.children.flatMap({ self.blockWithID($0, inOutline: outline) })
let filtered = self.filterBlocks(blocks, forMode: mode)
return BlockGroup(block : block, children : filtered)
}
Expand Down
18 changes: 18 additions & 0 deletions Test/CourseOutlineQuerierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,22 @@ class CourseOutlineQuerierTests: XCTestCase {
removable.remove()

}

func testMissingChildFilteredOut() {
let outline = CourseOutline(root: "root", blocks:
[
"root": CourseBlock(type: CourseBlockType.Section,
children: ["found", "missing"], blockID: "root", name: "Root!", multiDevice: true),
"found": CourseBlock(type: CourseBlockType.Section,
children: [], blockID: "found", name: "Child!", multiDevice: true)
]
)
let querier = CourseOutlineQuerier(courseID: courseID, outline: outline)
let childStream = querier.childrenOfBlockWithID(nil, forMode: .Full)
childStream.listenOnce(self) {
XCTAssertEqual($0.value!.children.count, 1)
XCTAssertEqual($0.value!.children[0].blockID, "found")
}
waitForStream(childStream)
}
}

0 comments on commit b4d9e5d

Please sign in to comment.