Skip to content

Instantly share code, notes, and snippets.

@simpulton
Created November 26, 2013 03:31
Show Gist options
  • Save simpulton/7653067 to your computer and use it in GitHub Desktop.
Save simpulton/7653067 to your computer and use it in GitHub Desktop.
Test for buildIndex
it.only('buildIndex should properly build an index', inject(function (RealtimeQuestion) {
var post = {
_id: 'p1',
comments: [
{_id: 'p2'},
{_id: 'p3'},
{_id: 'p4'}
],
answers: [
{_id: 'p5'},
{_id: 'p6', comments: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]}
]
};
var index = {
'p1': {obj: { _id: 'p1', comments: [
{_id: 'p2'},
{_id: 'p3'},
{_id: 'p4'}
], answers: [
{_id: 'p5'},
{_id: 'p6', comments: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]}
]}, collection: []},
'p2': {obj: {_id: 'p2'}, collection: [
{_id: 'p2'},
{_id: 'p3'},
{_id: 'p4'}
]},
'p3': {obj: {_id: 'p3'}, collection: [
{_id: 'p2'},
{_id: 'p3'},
{_id: 'p4'}
]},
'p4': {obj: {_id: 'p4'}, collection: [
{_id: 'p2'},
{_id: 'p3'},
{_id: 'p4'}
]},
'p5': {obj: {_id: 'p5'}, collection: [
{_id: 'p5'},
{_id: 'p6', comments: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]}
]},
'p6': {obj: {_id: 'p6', comments: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]}, collection: [
{_id: 'p5'},
{_id: 'p6', comments: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]}
]},
'p7': {obj: {_id: 'p7'}, collection: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]},
'p8': {obj: {_id: 'p8'}, collection: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]},
'p9': {obj: {_id: 'p9'}, collection: [
{_id: 'p7'},
{_id: 'p8'},
{_id: 'p9'}
]}
};
RealtimeQuestion.buildIndex(post).should.deep.equal(index);
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment