Skip to content

Commit

Permalink
Pass all tests with es6
Browse files Browse the repository at this point in the history
  • Loading branch information
xouabita committed Mar 27, 2016
1 parent 1ad6c24 commit 29eb4f2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 279 deletions.
27 changes: 0 additions & 27 deletions examples/simple.coffee

This file was deleted.

29 changes: 0 additions & 29 deletions examples/unique_and_id.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion src/extract_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function extractLists(attrs, paths) {
noLists.push(path)
else
for (var elt of newAttrs)
noLists = noLists.concat(extractLists(elt, {path: after, type}))
noLists = noLists.concat(extractLists(elt, [{path: after, type}]))
}

return noLists
Expand Down
220 changes: 0 additions & 220 deletions test/index.coffee

This file was deleted.

43 changes: 41 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,27 @@ class ListID extends Model {
}
}

class NestedList extends Model {
get Schema() {
return t.struct({
comments: t.list(t.struct({
content: t.String,
likes: t.list(t.ID(User))
}))
})
}
}

async function removeAll() {
await Promise.all([
Test.remove(),
TestUnique.remove(),
NoSchema.remove(),
Invalid.remove(),
User.remove(),
MaybeID.remove()
MaybeID.remove(),
ListID.remove(),
NestedList.remove()
])

try {
Expand All @@ -78,7 +91,9 @@ async function removeAll() {
NoSchema._collection().dropIndexes(),
Invalid._collection().dropIndexes(),
User._collection().dropIndexes(),
MaybeID._collection().dropIndexes()
MaybeID._collection().dropIndexes(),
ListID._collection().dropIndexes(),
NestedList._collection().dropIndexes()
])
} catch (e) {}
}
Expand Down Expand Up @@ -246,3 +261,27 @@ test('It should fail if there is an invalid ID in the list', async t => {
}
t.fail()
})

test('It should work with nested list', async t => {
var a = new User({name: 'qux'})
var b = new Test({mandatory: 'nooooo'})
var c = new User({name: 'jabita'})
await Promise.all([a.save(), b.save(), c.save()])
var nl = new NestedList({
comments: [{
content: 'foobarlol',
likes: [`${a.get('_id')}`, `${c.get('_id')}`]
}]
})
await nl.save()
nl.set('comments.1', {
content: 'mdrbar',
likes: [`${a.get('_id')}`, `${b.get('_id')}`]
})
try {
await nl.save()
} catch (e) {
return
}
t.fail()
})

0 comments on commit 29eb4f2

Please sign in to comment.