Completed
Push — master ( 0c15fd...9d8885 )
by Wallace
02:03
created

database.test.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 1
rs 10
1
/**
2
 * Database test
3
 */
4
'use strict'
5
6
const path = require('path')
7
const chai = require('chai')
8
const expect = chai.expect
9
10
chai.use(require('chai-fs'))
11
12
const database = require('../bin/database')
13
14
const file = path.join(__dirname, '../test/files/db.json')
15
const db = database.setFile(file)
16
17
describe('Test database', function () {
18
  before(function () {
19
    db.add('subtitle', 'pob').store()
20
    db.addEnv({'MOOV_SEARCH': 'dope'})
21
  });
22
23
  it ('expect to return an error if file is not a json', function () {
24
    expect(() => { database.setFile('../db.txt') }).to.throw('The database file must be a json file')
25
  })
26
27
  it ('expect database to be a string and equal parameter', function () {
28
    expect(db.database)
29
      .to.be.a('string')
30
      .to.be.equal(file)
31
  })
32
33
  it ('expect to be an object and contains subtitle property', function () {
34
    expect(db.add('subtitle', 'pob').data)
35
      .to.be.an('object')
36
      .to.have.property('subtitle', 'pob')
37
  })
38
39
  it ('expect file to exists and is a json', function () {
40
    expect(file)
0 ignored issues
show
introduced by
The result of the property access to expect(file).to.be.a.file().with.json is not used.
Loading history...
41
      .to.be.a.file()
42
      .with.json
43
  })
44
45
  it ('expect an error if file can\'t be created', function () {
46
    expect(database.setFile('/home/db.json').add('key', 'value').store())
0 ignored issues
show
introduced by
The result of the property access to expect(database.setFile(...store()).to.be.an.error is not used.
Loading history...
47
      .to.be.an.error
48
  })
49
50
  it ('expect to be an empty object', function () {
51
    expect(database.setFile('/home/db.json').get())
0 ignored issues
show
introduced by
The result of the property access to expect(database.setFile(...n("object").to.be.empty is not used.
Loading history...
52
      .to.be.an('object')
53
      .to.be.empty
54
  })
55
56
  it ('expect to be an not empty object', function () {
57
    expect(database.setFile(file).get())
0 ignored issues
show
introduced by
The result of the property access to expect(database.setFile(...("object").to.not.empty is not used.
Loading history...
58
      .to.be.an('object')
59
      .to.not.empty
60
  })
61
62
  it ('expect to be an object and contains subtitle', function () {
63
    expect(db.get())
64
      .to.be.an('object')
65
      .to.have.property('subtitle', 'pob')
66
  })
67
68
  it ('expect to be a string and is equal pob', function () {
69
    expect(db.get('subtitle'))
70
      .to.be.an('string')
71
      .to.be.equal('pob')
72
  })
73
74
  it ('expect an error if key don\'t exists in file', function () {
75
    expect(() => { db.get('potatoes') })
76
      .to.throw('potatoes is undefined')
77
  })
78
79
  it ('expect an error if typeof is not a object', function () {
80
    expect(() => { db.massive('test') })
81
      .to.throw('data must be an object')
82
  })
83
84
  it ('expect to be an object', function () {
85
    expect(db.massive({'subtitle': 'pob', 'quality': '720p'}).data)
86
      .to.be.an('object')
87
      .to.have.property('subtitle')
88
  })
89
90
  it ('expect an error if parameter is not a object', function () {
91
    expect(() => { db.addEnv('test') })
92
      .to.throw('data must be an object')
93
  })
94
95
  it ('expect to be an object and contains search', function () {
96
    expect(process.env)
97
      .to.be.an('object')
98
      .to.have.property('MOOV_SEARCH')
99
  })
100
})
101