๐Ÿ“ฆ ibakaidov / cover-test-task

๐Ÿ“„ db.js ยท 29 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29const {expect} = require('chai')
const DB = require('../src/js/db')

describe('db', () => {
  before(() => {
    this.db = DB.instance
  })

  it('should add and delete post', (done) => {
    const id = 1
    this.db.addPost({ id }).then((res) => {
      expect(res.id).eq(id)
      this.db.deletePost({id}).then(()=>{
        done()
      }).catch(done)
    }).catch(done)
  })

  it('should find today post', (done)=>{
    const id = 2
    this.db.addPost({ id }).then((res) => {
      expect(res.id).eq(id)
      this.db.getTodayPosts().then((posts)=>{
        expect(posts.length).gt(0)
        done()
      })
    }).catch(done)
  })
})