Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): simple active tasks implementation
- Loading branch information
1 parent
d5bb7bd
commit 0680c0a
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
|
||
describe('test.active_tasks.js', function () { | ||
|
||
afterEach(function (done) { | ||
PouchDB.activeTasks.tasks = [] | ||
return done(); | ||
}); | ||
|
||
it('Can add a task', function () { | ||
const task1 = {name: 'lol', total_items: 12} | ||
const id1 = PouchDB.activeTasks.add(task1) | ||
id1.should.be.a('string') | ||
}); | ||
|
||
it('Can get tasks by id', function () { | ||
const task2 = {name: 'wat', total_items: 546} | ||
const id2 = PouchDB.activeTasks.add(task2) | ||
const got2 = PouchDB.activeTasks.get(id2) | ||
got2['id'].should.equal(id2) | ||
}); | ||
|
||
it('Can get all tasks', function () { | ||
const task1 = {name: 'lol', total_items: 12} | ||
const task2 = {name: 'wat', total_items: 546} | ||
const id1 = PouchDB.activeTasks.add(task1) | ||
const id2 = PouchDB.activeTasks.add(task2) | ||
PouchDB.activeTasks.update(id1, {"completed_items": 2}) | ||
PouchDB.activeTasks.update(id2, {"completed_items": 213}) | ||
const list = PouchDB.activeTasks.list() | ||
const got2 = PouchDB.activeTasks.get(id2) | ||
list.length.should.equal(2) | ||
list[0]['id'].should.equal(id1) | ||
list[1]['id'].should.equal(id2) | ||
}); | ||
|
||
it('Can update a task', function () { | ||
const task1 = {name: 'lol', total_items: 12} | ||
const task2 = {name: 'wat', total_items: 546} | ||
const id1 = PouchDB.activeTasks.add(task1) | ||
const id2 = PouchDB.activeTasks.add(task2) | ||
PouchDB.activeTasks.update(id1, {"completed_items": 2}) | ||
PouchDB.activeTasks.update(id2, {"completed_items": 213}) | ||
const got1 = PouchDB.activeTasks.get(id1) | ||
const got2 = PouchDB.activeTasks.get(id2) | ||
got1['completed_items'].should.equal(2) | ||
got2['completed_items'].should.equal(213) | ||
got2['updatedAt'].should.be.a('string') | ||
}); | ||
|
||
it('Can remove a task', function () { | ||
const task1 = {name: 'lol', total_items: 12} | ||
const task2 = {name: 'wat', total_items: 546} | ||
const id1 = PouchDB.activeTasks.add(task1) | ||
const id2 = PouchDB.activeTasks.add(task2) | ||
PouchDB.activeTasks.update(id1, {"completed_items": 2}) | ||
PouchDB.activeTasks.update(id2, {"completed_items": 213}) | ||
PouchDB.activeTasks.remove(id1) | ||
const got2 = PouchDB.activeTasks.get(id2) | ||
PouchDB.activeTasks.tasks.length.should.equal(1) | ||
got2['id'].should.equal(id2) | ||
}); | ||
|
||
}); |