diff --git a/server/books/schema/nodes/snapshot.py b/server/books/schema/nodes/snapshot.py index c9f1e301..a856c030 100644 --- a/server/books/schema/nodes/snapshot.py +++ b/server/books/schema/nodes/snapshot.py @@ -156,10 +156,10 @@ class SnapshotNode(DjangoObjectType): @staticmethod def resolve_changes(parent, info, **kwargs): return { - 'hidden_objectives': 0, - 'new_objectives': 0, + 'hidden_objectives': parent.hidden_objectives.count(), + 'new_objectives': parent.custom_objectives.filter(hidden=False).count(), 'hidden_content_blocks': parent.hidden_content_blocks.count(), - 'new_content_blocks': parent.custom_content_blocks.count() + 'new_content_blocks': parent.custom_content_blocks.filter(hidden=False).count() } @staticmethod diff --git a/server/books/tests/test_snapshots.py b/server/books/tests/test_snapshots.py index 4455806e..ca08cf3d 100644 --- a/server/books/tests/test_snapshots.py +++ b/server/books/tests/test_snapshots.py @@ -87,6 +87,12 @@ SNAPSHOT_MODULE_QUERY = """ query SnapshotDetail($id: ID!) { snapshot(id: $id) { id + changes { + newContentBlocks + newObjectives + hiddenContentBlocks + hiddenObjectives + } objectiveGroups { title id @@ -174,9 +180,10 @@ class CreateSnapshotTestCase(SkillboxTestCase): module=self.module, title=self.title_custom, slug='cb-c') # content block d is user created, but hidden - self.custom_hidden_content_block = ContentBlockFactory(parent=self.chapter, owner=self.teacher, user_created=True, - module=self.module, title=self.title_custom_hidden, - slug='cb-d') + self.custom_hidden_content_block = ContentBlockFactory(parent=self.chapter, owner=self.teacher, + user_created=True, + module=self.module, title=self.title_custom_hidden, + slug='cb-d') # content block a and c are visible to school class X self.hidden_content_block.hidden_for.add(self.skillbox_class) self.custom_content_block.visible_for.add(self.skillbox_class) @@ -339,6 +346,12 @@ class CreateSnapshotTestCase(SkillboxTestCase): self.assertEqual(objective_group2['hidden'], True) + changes = snapshot['changes'] + self.assertEqual(changes['newContentBlocks'], 1) + self.assertEqual(changes['hiddenContentBlocks'], 1) + self.assertEqual(changes['newObjectives'], 1) + self.assertEqual(changes['hiddenObjectives'], 1) + def test_apply_initial_snapshot(self): teacher2 = User.objects.get(username='teacher2') teacher2_client = self.get_client(user=teacher2)